Error/Msg Box to appear if Cells dont match

ardykav

Board Regular
Joined
Oct 18, 2015
Messages
172
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a sheet where employees submit weekly activity figures.

They enter figures in section A and Section B where the totals are in Cell A25 and A60. At the end they then click a button (in a macro called "Submit")to submit the figures. What i want is a message or error box to pop up if cell A25 does not equal cell A60 when the button is pressed.

All help greatly appreciated,

thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
post the code you already have and someone will help you modify it !!
 
Upvote 0
post the code you already have and someone will help you modify it !!

Code below, i have highlighted in red where i would like to place the code and what i need it to do. thanks
Sub SUBMIT()
If MsgBox("Are you sure all figures on this page are correct?", vbYesNo) = vbNo Then Exit Sub
This is the part where i would like the code to be put, so it would be if A25<>A60 then a message box to appear
ActiveWorkbook.Sheets("YS").Visible = xlSheetVisible
Sheets("WSE").Select
SubmitStats
submitotherstats
ActiveWorkbook.Sheets("YS").Visible = xlSheetVeryHidden
ActiveWorkbook.RefreshAll
Sheets("WSE").Select
Range("A1").Select
MsgBox ("All Reports have been updated!")

End Sub
 
Upvote 0
Code:
[COLOR=#333333]Sub SUBMIT()[/COLOR]
[COLOR=#333333]If MsgBox("Are you sure all figures on this page are correct?", vbYesNo) = vbNo Then Exit Sub[/COLOR]

If Sheets("sheetname").Range("A25").Value <> Sheets("sheetname").Range("A60").Value Then
    MsgBox "Whatever you want to say."
    Exit Sub      'If you do not want anything else to be done if those two cells dont match.
End if 

[COLOR=#333333]ActiveWorkbook.Sheets("YS").Visible = xlSheetVisible[/COLOR]
[COLOR=#333333]Sheets("WSE").Select[/COLOR]
[COLOR=#333333]SubmitStats[/COLOR]
[COLOR=#333333]submitotherstats[/COLOR]
[COLOR=#333333]ActiveWorkbook.Sheets("YS").Visible = xlSheetVeryHidden[/COLOR]
[COLOR=#333333]ActiveWorkbook.RefreshAll[/COLOR]
[COLOR=#333333]Sheets("WSE").Select[/COLOR]
[COLOR=#333333]Range("A1").Select[/COLOR]
[COLOR=#333333]MsgBox ("All Reports have been updated!")[/COLOR]

[COLOR=#333333]End Sub[/COLOR]

Is this what you're looking for?

Also, Im wondering why you change the visibility of the sheets back and forth. A sheet does not need to be visible to be altered.
 
Upvote 0
Thanks so much thats exactly what i was looking for thats awesome!

The reason why i make that sheet visible back and forth is that an error appears when i press submit and the sheet is not visible. One of the macros transfers data onto that sheet. Is there a way around this error?
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,539
Members
449,038
Latest member
Guest1337

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