Newbie with VBA

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
 
A

Anders S

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
 

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

Top