Prevent Marco from running if # in cell is incorrect

Fixxer49

New Member
Joined
Jun 7, 2012
Messages
8
Hi,
I recorded a macro and created a button to run it. Everything works. I would like to prevent the macro from running (when the button is clicked) if cell F56 does not equal 100. Perhaps a warning pops up saying "Total Does Not Equal 100". If F56 equals 100 then the macro can run. Thanks in advance for the help!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
At the beginning of your macro add this:

Code:
Sub fixxer49()

If Range("F56").Value <> 100 Then

    MsgBox "Total Does Not Equal 100"
    
    Exit Sub
    
End If

End Sub
 
Upvote 0
Insert this snippet at the beginning of your macro:

Code:
If Range("F56") <> 100 Then
MsgBox "TOTAL NOT EQUAL TO 100!",vbInformation, "INVALID TOTAL"
Exit Sub
End If
Code:
 
Upvote 0
Below is the Macro. Cell F56 is in the "PM Analyst Results" tab. Cell F56 is the sum of F9:F53 in the "PM Analyst Results". Thanks again for all the help!



Sub SubmitandSend()
'
' SubmitandSend Macro
'

'
Range("A9:G53").Select
ActiveWindow.SmallScroll Down:=-21
ActiveWorkbook.Worksheets("PM Analyst Results").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("PM Analyst Results").Sort.SortFields.Add Key:= _
Range("F9:F53"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("PM Analyst Results").Sort
.SetRange Range("A9:G53")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A2:G2").Select
Application.Dialogs(xlDialogSendMail).Show
End Sub
 
Upvote 0
Thanks for the help! The insert didn't seem to work. It worked when i simply typed 100 into the cell F56 but when F56 was summing other cells to equal 100 the macro wouldn't work. Again, i really appreciate the help.
 
Upvote 0
i spoke too soon... it looks like it is a rounding issue. it seems even though the formatting only in F56 goes out two decimal places if you increase it you can see that it is not exactly 100. is there a way to truncate?
 
Upvote 0

Forum statistics

Threads
1,207,110
Messages
6,076,604
Members
446,216
Latest member
BEEALTAIR

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