mercredi 12 octobre 2016

Excel If syntax, how to determine whether the sentence has the keyword I am looking for

If InStr(1, UCase(CStr(compare_DU_ID)), "L4L", 1) >= 1 Then
                    If UCase(CStr(compare_DU_ID)) = UCase(CStr(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, CStr(compare_DU_ID), CStr(DU_ID), 1) = 1 Then
                        Worksheets("Sheet2").Cells(y, 97).Value = Updated_Date
                ElseIf InStr(1, CStr(DU_ID), CStr(compare_DU_ID), 1) = 1 Then
                        Worksheets("Sheet2").Cells(y, 97).Value = Updated_Date
                End If

I have a problem to update the date. For instances, 1st scenario, if the CStr(DU_ID) = 1731WG and CStr(compare_DU_ID) = 31731WG, then the date won't be updated. 2nd scenario, when CStr(DU_ID) = 1392WG and CStr(compare_DU_ID) = 11392WG, the date will be updated ..

What do I need to adjust to the code, so that second scenario won't be changed as well ...

Many thanks!

Aucun commentaire:

Enregistrer un commentaire