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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,651
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
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

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
5,129
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,195,712
Messages
6,011,266
Members
441,598
Latest member
chrispaulpearce

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
Top