excel 2007 messagebox macro help

lafhunting

New Member
Joined
Apr 6, 2013
Messages
6
I have a running total in B2 from cells D4,G4 and H4, If the number in B2 goes to a negative number I need a message box to automaticly pop up stating that you have a negative balance


I have tried several macros and no luck
Sub balance ()
if range("B2") < 0 then
msgbox "Check Your Balance!"
End If
End Sub

any HELP would be greatful







<colgroup><col><col><col span="5"></colgroup><tbody>
</tbody>
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Change to this and paste into the sheet module
Code:
Sub worksheet_Change(ByVal target As Range)
If Range("B2") < 0 Then
MsgBox "Check Your Balance!"
End If
End Sub
 
Upvote 0
Hi lafhunting,

Try this event macro* on the sheet in question:

Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

    If [B2].Value < 0 Then
    
        MsgBox "Check your balance!"
    
    End If

End Sub

* To install this macro follow these four steps:

1. Copy my suggested code to the clipboard (Ctrl + C)
2. Right click on the tab you wish to apply the code to and from the shortcut menu select View Code
3. Paste in my code (Ctrl + V) from step 1
4. From the File menu select Close and Return to Microsoft Excel

Note you could also do this via an If statement worksheet formula with conditional formatting to make it stand out.

HTH

Robert
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,937
Members
448,534
Latest member
benefuexx

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