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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,858
Messages
6,121,956
Members
449,057
Latest member
FreeCricketId

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