Thread: Code to compare
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
cht13er cht13er is offline
external usenet poster
 
Posts: 141
Default Code to compare

On Apr 1, 5:45 pm, acss wrote:
Is there code that would perform a compare btween two columns and should the
values not be the same then a yes/no message box can appear to alert the
user?


Yes there is. It would likely look something like this...

Private Sub CompareColumns()

Dim iCounter as Integer
Dim bnSame as Boolean

Do For iCounter = 1 to 150 'this gets changed depending on how many
rows you want to compare
If Cells(iCounter,1).Value = Cells(iCounter,2).Value Then
'if any value in column A = in column B
bnSame = True
iCounter = 150 'don't keep checking
End If
Loop

If bnSame = True Then
Msgbox "At least one identical value"
End If

End Sub

Throw that into a new module once you are in the VBE (Ctrl+F11) ...
post back with any more questions!

HTH

Chris