VBA Code for Message Box to Appear when range in cell is greater than 0

zNyteAngel

New Member
Joined
Nov 9, 2011
Messages
12
Hi,

I need help with a VBA code to appear when a particular column (G) has data entered in it that is greater than 0.

I have tried 6 different codes and they did not produce the result I needed.

Please help!

Thanks,
Bekah
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,388
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi,

I need help with a VBA code to appear when a particular column (G) has data entered in it that is greater than 0.

I have tried 6 different codes and they did not produce the result I needed.

Please help!

Thanks,
Bekah
What do you want the message to be? Do you want to allow an entry greater than 0 to remain or do you want to remove it?
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
Hi and welcome to the board.
Assuming the changes to column G will be manually entered (or cut/copied & pasted - NOT a formula updating) then something like this in the worksheet module should get you started.
Right click the sheet tab & choose View Code. Paste this in the sheet module.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'Specify to work only with single cell changes
If Target.Count > 1 Then Exit Sub

'Specify to work only when a cell in column G changes.
If Target.Column <> 7 Then Exit Sub

If Target.Value > 0 Then MsgBox "HEY!!! Column G has a value greater than zero."

End Sub
press Alt+Q (to close the vb editor) and make an entry in your sheet to check it out.

If your column G changes happen because of formulas updating, (instead of manual entries) let us know and we can fix it to use the sheet calculation event instead of the sheet change event.

Hope it helps.
 

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,701
Office Version
  1. 2016
Platform
  1. Windows
Welcome to the Forum,

Have you looked at the worksheet and selected the Tab and used the right mouse button and then View Code. You can select some options from there, Change the first drop down to Worksheet and the second drop down to Calculate or Change and place in an if statement.

Or would a normal if statement be useful on the sheet to determine if the value is greater than Zero.

What do you want to Happen to the Cell?


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column <> 7 Then Exit Sub
If Target.Value > 0 Then MsgBox "The value added is greater than Zero."
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,822
Messages
5,598,304
Members
414,224
Latest member
Crazy_FC

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