VBA compare to column values

i am new to VBA what i want to do is if cell column A is empty then cell in column B should also be empty and if cell column A as values then cell in columns B should have value in same row. if not meet then msg box error my code is below i have problems with 2nd of that condition its not showing me error when i have value in cell in column B but column A is empty. Pls help

Sub Denial_Reason1()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet3")
Dim lr As Long, target As Range

lr = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
For Each target In ws.Range("A2:A" & lr)
   If target <> "" And target.Offset(0, 1) = "" Then
    MsgBox "Error" & target.Address
    enter code here

   ElseIf target = "" And target.Offset(0, 1) <> "" Then
    MsgBox "Error" & target.Address
End If

  Next target
End Sub

Read more here: https://stackoverflow.com/questions/64937810/vba-compare-to-column-values

Content Attribution

This content was originally published by kyohans05 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: