Message box to show if there is a value that is not zero in certain cells when opening workbook

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have tried to write code to show a message if either H11 or H24 has a value that is not zero

No message box pops up where there is a zero that is not zero

Code:
 Private Sub Variance()
With Sheets("Sales Recon")
If .Range("H11") Or .Range("H24") <> 0 Then
MsgBox "There is a variance"

 
End With

End Sub


It would be appreciated if someone could amend this
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi,

Below code will show message box when either H11 or H24 has non-zero value.

VBA Code:
Private Sub Variance()
    With Sheets("Sales Recon")
        If .Range("H11") <> 0 Or .Range("H24") <> 0 Then
            MsgBox "There is a variance"
        End If
    End With

End Sub
 
Upvote 0
Hi Howard,

The code is showing the message box. See Image.

Do you need to display any specific message/ value ?

Thanks,
Saurabh
 

Attachments

  • variance.PNG
    variance.PNG
    31.5 KB · Views: 3
Upvote 0
Thanks for the reply

I placed this code in the workbook module and when I open the workbook the message box showing the message does not appear

Not sure why message box does not display on my workbook as per your image
 
Upvote 0
Hi Howard,

If you like to show message box when workbook opens then write macro on workbook open event.

Replace your code from below.

VBA Code:
Private Sub Workbook_Open()
        With Sheets("Sales Recon")
        If .Range("H11") <> 0 Or .Range("H24") <> 0 Then
            MsgBox "There is a variance"
        End If
    End With
End Sub
 
Upvote 0
Many thanks for the help. It works perfectly
 
Upvote 0

Forum statistics

Threads
1,213,564
Messages
6,114,334
Members
448,567
Latest member
Kuldeep90

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