判定メモ20171112
'判定は無理だと思うんだよなOption ExplicitPrivate Declare Function timeGetTime Lib "winmm.dll" () As Long#If VBA7 ThenPrivate Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As LongPtr)#ElsePrivate Declare Sub Sleep Lib "kernel32" (ByVal ms As Long)#End IfSub decision01() Dim i_time As Long '開始時間 i_time = timeGetTime() Application.ScreenUpdating = False Dim i, j As Long Dim ASKword, estaWord As String Dim ASKwordCount, estawordCount, estawordLast As Long Dim judge1 As Long ASKword = Worksheets("判定").Range("B2") estaWord = Worksheets("判定").Range("B4") '先ずはASKとe-sta両方のスペースの除去 '半角にして、" "(半角スペース)を '""にして取り除く '半角にする ASKword = StrConv(ASKword, vbNarrow) estaWord = StrConv(estaWord, vbNarrow) 'Substuteで" "→"" ASKword = WorksheetFunction.Substitute(ASKword, " ", "") estaWord = WorksheetFunction.Substitute(estaWord, " ", "") '略称となりうる文字列を含んでいるか探す 'それと略していない形の文字列をもう一方で探す '存在していたら、同じ組織の単位として扱う 'Dim ASKword, estaWord, ryk As String Dim Count1, Count2 As Long 'ASKword = Worksheets("判定").Range("B2") 'estaWord = Worksheets("判定").Range("B4") With Worksheets("組織単位略称一覧") For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row Count1 = InStr(ASKword, .Cells(i, 2)) If Count1 <> 0 Then Count2 = InStr(estaWord, StrConv(.Cells(i, 3), vbNarrow)) If Count2 <> 0 Then ASKword = WorksheetFunction.Substitute(ASKword, .Cells(i, 2), .Cells(i, 3)) Else End If Else End If Next End With With Worksheets("組織単位略称一覧") For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row Count1 = InStr(estaWord, .Cells(i, 2)) If Count1 <> 0 Then Count2 = InStr(ASKword, StrConv(.Cells(i, 3), vbNarrow)) If Count2 <> 0 Then estaWord = WorksheetFunction.Substitute(estaWord, .Cells(i, 2), .Cells(i, 3)) Else End If Else End If Next End With ASKword = StrConv(ASKword, vbNarrow) estaWord = StrConv(estaWord, vbNarrow) Debug.Print "ASK : " & ASKword & " e-sta : " & estaWord 'ここで一旦判定してみる If ASKword = estaWord Then Debug.Print "一致" End End If With Worksheets("判定") ASKwordCount = Len(ASKword) 'ASK文字数 estawordCount = Len(estaWord) 'e-sta文字数 Debug.Print "ASK:" & ASKwordCount & " e-sta:" & estawordCount 'e-staの最後の文字があるところを探す estawordLast = InStr(1, ASKword, Right(estaWord, 1)) '最後の文字が入っていなかったら不一致 If estawordLast = 0 Then 'ここ必要ないかも 一応、判定一回目 Debug.Print "不一致" Debug.Print Format$(timeGetTime - i_time) & " ミリ秒" Application.ScreenUpdating = True End End If Debug.Print "e-staの最後の文字はASKの" & estawordLast & "文字目" Debug.Print "比較対象は" & Left(ASKword, InStr(1, ASKword, Right(estaWord, 1))) For i = 1 To ASKwordCount judge1 = InStr(1, ASKword, Right(estaWord, i)) Next If judge1 = 1 Then Debug.Print "一致" Else Debug.Print "次の処理へ" End If End With '処理時間 Debug.Print Format$(timeGetTime - i_time) & " ミリ秒" Application.ScreenUpdating = TrueEnd SubFunction 略称を戻す(ByVal ASKword As String, ByVal estaWord As String) '略称となりうる文字列を含んでいるか探す 'それと略していない形の文字列をもう一方で探す '存在していたら、同じ組織の単位として扱う 'Dim ASKword, estaWord, ryk As String Dim i, j, Count1, Count2 As Long 'ASKword = Worksheets("判定").Range("B2") 'estaWord = Worksheets("判定").Range("B4") With Worksheets("組織単位略称一覧") For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row Count1 = InStr(ASKword, .Cells(i, 2)) If Count1 <> 0 Then Count2 = InStr(estaWord, StrConv(.Cells(i, 3), vbNarrow)) If Count2 <> 0 Then ASKword = WorksheetFunction.Substitute(ASKword, .Cells(i, 2), .Cells(i, 3)) Else End If Else End If Next End With With Worksheets("組織単位略称一覧") For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row Count1 = InStr(estaWord, .Cells(i, 2)) If Count1 <> 0 Then Count2 = InStr(ASKword, StrConv(.Cells(i, 3), vbNarrow)) If Count2 <> 0 Then estaWord = WorksheetFunction.Substitute(estaWord, .Cells(i, 2), .Cells(i, 3)) Else End If Else End If Next End With ASKword = StrConv(ASKword, vbNarrow) estaWord = StrConv(estaWord, vbNarrow) Debug.Print "ASK : " & ASKword & " e-sta : " & estaWord Dim refdate(1) As Variant refdate(0) = ASKword refdate(1) = estaWord 略称を戻す = refdate()End FunctionSub decision03() Dim i_time As Long '開始時間 i_time = timeGetTime() Application.ScreenUpdating = False Dim i, j As Long Dim ASKword, estaWord As String Dim ASKwordCount, estawordCount, estawordLast As Long Dim judge1 As Long ASKword = Worksheets("判定").Range("B2") estaWord = Worksheets("判定").Range("B4") '先ずはASKとe-sta両方のスペースの除去 '文字コードASCにして、" "(半角スペース)を '""にして取り除く 'ASCで囲む ASKword = StrConv(ASKword, vbNarrow) estaWord = StrConv(estaWord, vbNarrow) 'Substuteで" "→"" ASKword = WorksheetFunction.Substitute(ASKword, " ", "") estaWord = WorksheetFunction.Substitute(estaWord, " ", "") Call 略称を戻す(ASKword, estaWord) Dim refdate(1) As Variant ASKword = refdate(0) estaWord = refdate(1) 'ここで一旦判定してみる If ASKword = estaWord Then Debug.Print "一致" End End If With Worksheets("判定") ASKwordCount = Len(ASKword) 'ASK文字数 estawordCount = Len(estaWord) 'e-sta文字数 Debug.Print "ASK:" & ASKwordCount & " e-sta:" & estawordCount 'e-staの最後の文字があるところを探す estawordLast = InStr(1, ASKword, Right(estaWord, 1)) '最後の文字が入っていなかったら不一致 If estawordLast = 0 Then 'ここ必要ないかも 一応、判定 Debug.Print "不一致" Debug.Print Format$(timeGetTime - i_time) & " ミリ秒" Application.ScreenUpdating = True End End If Debug.Print "e-staの最後の文字は" & estawordLast & "文字目" Debug.Print "比較対象は" & Left(ASKword, InStr(1, ASKword, Right(estaWord, 1))) For i = 1 To ASKwordCount judge1 = InStr(1, ASKword, Right(estaWord, i)) Next If judge1 = 1 Then Debug.Print "一致" Else Debug.Print "次の処理へ" End If End With '処理時間 Debug.Print Format$(timeGetTime - i_time) & " ミリ秒" Application.ScreenUpdating = TrueEnd SubSub decision02()'部課の単位を探して挟む''''' Dim i_time As Long '開始時間 i_time = timeGetTime() Application.ScreenUpdating = False Dim i, j As Long Dim ASKword, estaWord As String Dim ASKwordCount, estawordCount, estawordLast As Long Dim judge1 As Long ASKword = Worksheets("判定").Range("B2") estaWord = Worksheets("判定").Range("B4") With Worksheets("判定") ASKwordCount = Len(ASKword) estawordCount = Len(estaWord) Debug.Print "ASK:" & ASKwordCount & " e-sta:" & estawordCount 'e-staの最後の文字があるところを探す estawordLast = InStr(1, ASKword, Right(estaWord, 1)) '最後の文字が入っていなかったら不一致 If estawordLast = 0 Then 'ここ必要ないかも Debug.Print "不一致" Debug.Print Format$(timeGetTime - i_time) & " ミリ秒" Application.ScreenUpdating = True End End If Debug.Print "e-staの最後の文字は" & estawordLast & "文字目" Debug.Print "比較対象は" & Left(ASKword, InStr(1, ASKword, Right(estaWord, 1))) For i = 1 To ASKwordCount judge1 = InStr(1, ASKword, Right(estaWord, i)) Next If judge1 = 1 Then Debug.Print "一致" Else Debug.Print "次の処理へ" End If End With '処理時間 Debug.Print Format$(timeGetTime - i_time) & " ミリ秒" Application.ScreenUpdating = True End SubFunction 略称を戻す1(ByVal ASKword As String, ByVal estaWord As String) '略称となりうる文字列を含んでいるか探す 'それと略していない形の文字列をもう一方で探す '存在していたら、同じ組織の単位として扱う 'Dim ASKword, estaWord, ryk As String Dim i, j, Count1, Count2 As Long 'ASKword = Worksheets("判定").Range("B2") 'estaWord = Worksheets("判定").Range("B4") With Worksheets("組織単位略称一覧") For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row Count1 = InStr(ASKword, .Cells(i, 2)) If Count1 <> 0 Then Count2 = InStr(estaWord, StrConv(.Cells(i, 3), vbNarrow)) If Count2 <> 0 Then ASKword = WorksheetFunction.Substitute(ASKword, .Cells(i, 2), .Cells(i, 3)) Else End If Else End If Next End With With Worksheets("組織単位略称一覧") For i = 2 To .Cells(Rows.Count, 2).End(xlUp).Row Count1 = InStr(estaWord, .Cells(i, 2)) If Count1 <> 0 Then Count2 = InStr(ASKword, StrConv(.Cells(i, 3), vbNarrow)) If Count2 <> 0 Then estaWord = WorksheetFunction.Substitute(estaWord, .Cells(i, 2), .Cells(i, 3)) Else End If Else End If Next End With ASKword = StrConv(ASKword, vbNarrow) estaWord = StrConv(estaWord, vbNarrow) Debug.Print "ASK : " & ASKword & " e-sta : " & estaWord Dim refdate(1) As Variant refdate(0) = ASKword refdate(1) = estaWord 略称を戻す = refdateEnd FunctionSub 組織単位を探す()End Sub