VBA pop up using multiple ranges/rows

Mattl1976

New Member
Joined
Jan 31, 2016
Messages
14
Hi I am currently using vba for a pop up message from column A depending on whether a certain value is shown as per below.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, r As Range
Set A = Range("A:A")
If Intersect(Target, A) Is Nothing Then Exit Sub
For Each r In Target
If r.Value = "2001708" Then
MsgBox "2 required per pump "
ElseIf r.Value = "10804" Then
MsgBox "use 2001708 for 220v pumps "
End If
Next r
End Sub


My question is how do I add another pop up if column B contains the text "rubber .25" with the pop up message saying "dont use rubber hose"

Thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r As Range
    
    Application.EnableEvents = False
    
    If Not Intersect(Target, Me.Columns("A")) Is Nothing Then
        For Each r In Intersect(Target, Me.Columns("A"))
            Select Case r.Value
                Case "2001708"
                    MsgBox "2 required per pump"
                Case "10804"
                    MsgBox "use 2001708 for 220v pumps"
            End Select
        Next r
    End If
    
    If Not Intersect(Target, Me.Columns("B")) Is Nothing Then
        For Each r In Intersect(Target, Me.Columns("B"))
            If InStr(1, r.Value, "rubber .25", vbTextCompare) > 0 Then
                MsgBox "dont use rubber hose"
            End If
        Next r
    End If

    Application.EnableEvents = True
End Sub
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r As Range
   
    Application.EnableEvents = False
   
    If Not Intersect(Target, Me.Columns("A")) Is Nothing Then
        For Each r In Intersect(Target, Me.Columns("A"))
            Select Case r.Value
                Case "2001708"
                    MsgBox "2 required per pump"
                Case "10804"
                    MsgBox "use 2001708 for 220v pumps"
            End Select
        Next r
    End If
   
    If Not Intersect(Target, Me.Columns("B")) Is Nothing Then
        For Each r In Intersect(Target, Me.Columns("B"))
            If InStr(1, r.Value, "rubber .25", vbTextCompare) > 0 Then
                MsgBox "dont use rubber hose"
            End If
        Next r
    End If

    Application.EnableEvents = True
End Sub
Hey thanks for sending through, unfortunately the second msg box for the rubber hose did not work. Still worked for the top section in the column A just not for the column B. For column B the rubber . 25 is just part of the text in the cell. Not sure if that makes a difference?
 
Upvote 0
For column B the rubber . 25 is just part of the text in the cell. Not sure if that makes a difference?
I suspected that was the case so I used the InStr() method. It's working on my end. Check if you place the code in the right sheet module.

Screen Shot 2024-05-19 at 10.56.02 PM.png
 
Upvote 0
I'm saying to check where you placed the code. It should be in your sheet module and not ThisWorkBook or the general module. Right-click on the sheet name -> View Code -> Paste in the code in the editor.
Screen Shot 2024-05-19 at 11.42.21 PM.png
 
Upvote 0
hm... You have a lot of workbooks open. Make sure it's the right workbook as well.
 
Upvote 0
Test the code out on a blank workbook. Does that work?
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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