fork download
  1. Option Explicit
  2.  
  3. Public Sub 単語変換()
  4. Const OutColNo As Long = 26 '出力列番号 Z列
  5. Const OutColSize As Long = 10 '出力列数
  6. Dim ws1 As Worksheet '単語帳
  7. Dim ws2 As Worksheet 'ししし
  8. Dim dicT As Object 'Dictionary キー:単語 値:置換単語
  9. Dim maxrow1 As Long
  10. Dim maxrow2 As Long
  11. Dim row1 As Long
  12. Dim row2 As Long
  13. Dim key As Variant
  14. Dim arr1 As Variant
  15. Dim arr2 As Variant
  16. Dim dicTkeys As Variant
  17. Dim str As String
  18. Dim i As Long
  19. Dim j As Long
  20. Dim out_ix As Long
  21. Dim t1 As Double
  22. Dim t2 As Double
  23. t1 = Timer
  24. Set ws1 = Worksheets("たたた")
  25. Set ws2 = Worksheets("ししし")
  26. Set dicT = CreateObject("Scripting.Dictionary") ' Dictionaryの定義
  27. maxrow1 = ws1.Cells(Rows.count, "A").End(xlUp).row 'A列目の最終行を求める
  28. maxrow2 = ws2.Cells(Rows.count, "V").End(xlUp).row 'V列目の最終行を求める
  29. For row1 = 2 To maxrow1
  30. key = ws1.Cells(row1, "A").Value
  31. If key <> "" Then
  32. dicT(key) = ws1.Cells(row1, "E").Value
  33. End If
  34. Next
  35. arr1 = ws2.Range("V2:V" & maxrow2)
  36. ReDim arr2(1 To UBound(arr1, 1), 1 To OutColSize)
  37. For i = 1 To UBound(arr2, 1)
  38. For j = 1 To OutColSize
  39. arr2(i, j) = ""
  40. Next
  41. Next
  42. dicTkeys = dicT.keys
  43. For i = 1 To UBound(arr1, 1)
  44. str = arr1(i, 1)
  45. out_ix = 0
  46. If str <> "" Then
  47. For Each key In dicTkeys
  48. If InStr(1, str, key, vbBinaryCompare) > 0 Then
  49. out_ix = out_ix + 1
  50. If out_ix > OutColSize Then Exit For
  51. arr2(i, out_ix) = dicT(key)
  52. End If
  53. Next
  54. End If
  55. Next
  56. ws2.Range(ws2.Cells(2, OutColNo), ws2.Cells(maxrow2, OutColNo + OutColSize - 1)).Value = arr2
  57. t2 = Timer
  58. MsgBox ("完了 " & t2 - t1 & "秒")
  59. End Sub
  60.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty