If statement VBA

michaelp1029

Board Regular
Joined
Jul 15, 2008
Messages
63
So here's the deal. I need to develop an "if" statement in my VBA code. In cell J7 of "Sheet 1" I have a dollar value that should match the value in cell D21 on "Sheet 2". So I want to have a button that I can press and if J7 Sheet 1 and D21 Sheet 2 are not the same, I would like a message box to appear stating "Numbers don't match. Please verify". But if the are equal, I want another message box to appear stating "Ok". I am a novice at VBA and could use some help.

Danke
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Heres the code you would need,

Draw a textbox and assign this macro to it
Code:
Sub Checkfigures()
If Sheets("Sheet1").Range("J7") = Sheets("Sheet2").Range("D21") Then
  MsgBox "Everything is OK", , "OK"
Else
  MsgBox "Numbers don't match. Please verify", , "Verify"
End If
End Sub
Cheers
GB
 
Upvote 0
Try...

Code:
Sub CheckValues()
    If Sheets("Sheet1").Range("J7").Value = Sheets("Sheet2").Range("D21").Value Then
    MsgBox "OK"
    Else
    MsgBox "Numbers don't match. Please verify"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top