Multiple MsgBox based on the same column but different keywords in the column

Wishful Thinking

New Member
Joined
Dec 31, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Here is my code on Sheet1 (Checkbook Ledger). However, per my code below, in range "B2:B1000" If "B2" is "Credit Card" I get the correct pop up - If "B3" is "License" then I get the correct popup. However after that "B4:B1000" I get the pop up associated with "License" regardless of the keyword inputted. Therefore, I only want the msgbox associated with the keyword (ex: "License" or "Credit Card") to pop up with associated msgbox. If neither of the keywords are found, I don't want any pop up to show. Also, I may find an additional keyword in range "B2:B1000" that I would like to have another pop up msgbox. What am I missing in the code to make it do what I want. Thanks for taking a look and if you need additional info, let me know.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Column = 2 Then Exit Sub
If Not Range("B2:B1000").Find(What:="License", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True) Is Nothing Then
MsgBox "Separate The Cost Of The Tag And The Cost Of The Property Tax - Then Create A Separate Entry For The Property Tax"
Exit Sub
End If
If Not Target.Column = 2 Then Exit Sub
If Not Range("B2:B1000").Find(What:="Credit Card", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True) Is Nothing Then
MsgBox "Separate The Cost Of Each Item - Create Separate Entries For House, Gas, Food, Vacation"
Exit Sub
End If

End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I think the problem with your code as it stands is that it is looking for those words every time there is a change in the range B2:B1000 - therefore, if you add "License" in a cell and don't change it afterwards your code will exit after it finds the (existing) "License" in the range. I suspect that you wanted the message boxes to run after the newly entered text was assessed only? If that is the case, try the following code instead:
Option Compare Text
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("B2:B1000"), Target) Is Nothing Then
    Application.EnableEvents = False
      If Target = "License" Then MsgBox "Separate The Cost Of The Tag And The Cost Of The Property Tax - Then Create A Separate Entry For The Property Tax"
      If Target = "Credit Card" Then MsgBox "Separate The Cost Of Each Item - Create Separate Entries For House, Gas, Food, Vacation"
    Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

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