Code to compare

  • Thread starter Thread starter acss
  • Start date Start date
A

acss

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?
 
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
 
Maybe if you could give me some more info. And what your data looks like in
the spreedsheet. I could cook you up something
 
It is really something simple like if user typed in column A the amount of
100 then Column b should automatically have that value and should it not
then a message box would appear or some sort of error flag.
 
Sub somethingSimple()
Const whatColumn = "A" 'Change to your needs
Dim looper As Long 'looper = 5 Starting row of data
Dim lastToCheckRow As Long
Dim cellPointer As Variant

lastToCheckRow = Range(whatColumn & Rows.Count).End(xlUp).Row

For looper = 1 To lastToCheckRow
Set cellPointer = Worksheets("Sheet1").Cells(looper, 1)
If cellPointer <> cellPointer.Offset(0, 1) Then
MsgBox "Range(" & cellPointer.Address & ")" _
& " does not match Range(" & _
cellPointer.Offset(0, 1).Address & ")"
End If
Next looper
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top