VBA Question - MsgBox pop up when any data added in one column?

nuvque

New Member
Joined
Jan 9, 2018
Messages
7
Hi everyone,

I am a complete newbie to VBA, and have googled my way to this point, but I can't seem to figure out how to add a message boxes when any information is entered into a certain column.

I have gotten the msgbox to work when I know the set value that will be entered as there is data validation on those cells, however in column BA, it could be any information at all could be entered. What I want is for a msgbox to pop up only when new data is entered, but at the moment, a msgbox appears when there are any changes at all in that range, including deleting the content, which I do not want.

Here is the full code - any suggestions would be really appreciated!

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("L2:L6000,K2:K6000,BM2:BM6000,AZ2:AZ6000")) Is Nothing Then
Select Case Target
Case "Notice": MsgBox (MsgBox ("text here")
Case "Risk": MsgBox ("text here")
Case "1000": MMsgBox ("text here")
Case "2000": MsgBox ("text here")
Case "A": MsgBox ("text here")
Case "B": MsgBox ("text here")
Case "C": MsgBox ("text here")
Case "D (MsgBox ("text here")
End Select
End If
If Not Intersect(Target, Range("BA2:BA6000")) Is Nothing Then
MsgBox ("text I want to display here"), vbInformation, "Reminder"
End If
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Welcome to the Board!

You could add another condition to see if the updated cell currently has any data in it, i.e.
Code:
If Target.Value <> "" Then
That would get rid of it returning the MsgBox when data is deleted.
 
Upvote 0
Welcome to the Board!

You could add another condition to see if the updated cell currently has any data in it, i.e.
Code:
If Target.Value <> "" Then
That would get rid of it returning the MsgBox when data is deleted.

Thanks for your quick response! Sorry I'm a complete newbie to VBA so I don't understand :( I have tried the following but it didn't work. Do I also need to insert anything specific in <> or "" as I've also left this blank?

Code:
If Target.Value <> "" Then
If Not Intersect(Target, Range("BA2:BA6000")) Is Nothing Then
    MsgBox ("text I want to display here"),
    End If
    End Sub
 
Upvote 0
One way to do it would be like this:
Code:
If Target.Value = "" Then Exit Sub

If Not Intersect(Target, Range("BA2:BA6000")) Is Nothing Then
    MsgBox ("text I want to display here"),
End If

End Sub
So, what that will do is if the Target is empty, exit the sub and don't do anything else.
That might be a little easier than nesting the IF statements.
 
Last edited:
Upvote 0
You are welcome.
Glad I was able to help!:)
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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