我认为InStr()中存在一个错误,任何人都可以确认吗?
例如,
场景1,keyword = "1392WG"
和searchString = "11392WG"
,如果您使用InStr(1, searchString, keyword, 1)
,结果将以1
结束。但如果是searchString = "31392WG"
,则结果将是2
。
有人可以测试吗?
`子测试()
Updated_Date = "2016-10-10" 'Date might need to change (values after equation, remember to add it between "")
LastRow_Sheet1 = Worksheets("Sheet1").UsedRange.Rows.Count
LastRow_Sheet2 = Worksheets("Sheet2").UsedRange.Rows.Count
For x = 3 To 3
DU_ID = Worksheets("Sheet1").Cells(x, 2).Value 'Cells(x, 2) might need to change
sting_DU_ID = UCase(CStr(DU_ID))
For y = 374 To 375
compare_DU_ID = Worksheets("Sheet2").Cells(y, 2).Value 'Cells(y, 2) might need to change
string_compare_DU_ID = UCase(CStr(compare_DU_ID))
If InStr(1, string_compare_DU_ID, "L4L", 1) >= 1 Then
If string_compare_DU_ID = sting_DU_ID Then 'If L4L in compare_DU_ID, then DU_ID definitely equals to compare_DU_ID
Worksheets("Sheet2").Cells(y, 97).Value = Updated_Date '1. Cells(y, 97) might need to change, depending on which contract date you want to update
End If
ElseIf InStr(1, string_compare_DU_ID, sting_DU_ID, 1) = 1 Then
Worksheets("Sheet2").Cells(y, 97).Value = Updated_Date
ElseIf InStr(1, sting_DU_ID, string_compare_DU_ID, 1) = 1 Then
Worksheets("Sheet2").Cells(y, 97).Value = Updated_Date
End If
Next
Next
End Sub
`