Newbie with VBA

  • Thread starter Thread starter Gun_Maddie
  • Start date Start date
G

Gun_Maddie

I am trying to compare two numbers in a spreadsheet, if they don't
equal then have a message box appear. Here is what I wrote. Any help
would be appreciated.

Sub ValidateSums()

Sheets("T&E Form").Select
If Range("P35") <> Range("P56") Then
MsgBox ("Invalid Amounts", vbRetryCancel, "Please correct
amounts")
End If

End Sub


Thanks
Mike
 
Hi Mike,

So what is the problem? The MsgBox I guess.

The following code seems to work:

'-----------------
Option Explicit

Sub ValidateSums()
Dim BtnClicked As Integer

Sheets("T&E Form").Activate
If Range("P35").Value <> Range("P56").Value Then
BtnClicked = MsgBox( _
Prompt:="Invalid Amounts", _
Buttons:=vbRetryCancel, _
Title:="Please correct amounts")

If BtnClicked = vbRetry Then
MsgBox "User clicked Retry"
Else
MsgBox "User clicked Cancel"
End If

End If
End Sub
'-----------------

HTH
Anders Silven
 
Back
Top