View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jason Jason is offline
external usenet poster
 
Posts: 367
Default Do Until€¦Loop Question for the Excel-Looping-Experts

Sorry I had a slight typo in the previous post. See revised code below.

Sub Compare_AB()

Dim cell As Range, rng As Range

Set rng = Range("A1:A" & Cells.SpecialCells(xlCellTypeLastCell).Row)

For Each cell In rng

If cell = cell.Offset(0, 1) Then
cell.Offset(0, 2) = "Yes"
Else
cell.Offset(0, 2) = "No"
End If

Next

End Sub

Also, if you want to leave a blank cell, rather than No, then delete the
full If function above, and replace with:

If cell = cell.Offset(0, 1) Then
cell.Offset(0, 2) = "Yes"
ElseIf cell = "" Or cell.Offset(0, 1) = "" Then
cell.Offset(0, 2) = ""
Else
cell.Offset(0, 2) = "No"
End If