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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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?
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,086
Members
448,944
Latest member
sharmarick

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