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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Gettingbetter

Well-known Member
Joined
Oct 12, 2004
Messages
602
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

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,149
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,191,118
Messages
5,984,749
Members
439,907
Latest member
Kayfabe

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
Top