IF Range is not equal to zero THEN msgbox

egiannaros

New Member
Joined
Mar 14, 2008
Messages
42
I am trying to write a macro that will look at a range of cells and tell me if ANY of those cells Does Not equal zero. The purpose of this macro is for data control.

This is what I have tried so far, but it is not working:

Code:
Public Sub Run_WD2_Recon()
 
If Range("C96:J108").Select <> 0 Then
MsgBox ("Variance Detected! Macro Will End Now.")
GoTo 10
 
'More VB Code will be added here at a later time.
 
10:
End If
I tested the code while all cells in the range have zero in them and I am incorrectly prompted by the Msgbox. What am I doing wrong? Thanks.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try changing

If Range("C96:J108").Select <> 0 Then

to

If Application.Countif(Range("C96:J108"),"<>0")>0 Then
 
Upvote 0
Thank you! It worked perfectly. I tested it with positive and negative variances.

This function will be very useful for other tasks I have as well!
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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