Brian H
Brian H

Reputation: 21

Else condition always happening

In the following code the else condition always happens, even if the two variables are different. If I remove it it works just as it should, but has empty spots where "No" should be written.

For i = 2 To lRowMas    'Loop through all rows in Master Sheet
    For j = 2 To lRowCurrentSheet    'Loop through all rows in sheet to compare
        If Sheets(masterSheet).Cells(i, 1) = Sheets(sheetNamesAsArray(x)).Cells(j, 1) Then
            Sheets(masterSheet).Cells(i, x + 2).Value = "Yes" 'set value to Yes
        Else
            Sheets(masterSheet).Cells(i, x + 2).Value = "No" 'set value to Yes
        End If
    Next j  'End inner loop, on sheet to compare
Next i  'End outer loop, on MasterSheet

Upvotes: 1

Views: 37

Answers (1)

Brian H
Brian H

Reputation: 21

I solved my problem. I forgot to add a End For, so once it found a match and wrote yes, it would overwrite it with no in the next iteration. Thank you all for your advice.

Upvotes: 1

Related Questions