If Cell Begins with Text, Msg box

jcipriano13

New Member
Joined
Apr 24, 2018
Messages
1
hi, I'm trying to create a line in my macro to show a msg box if cells in a give range begin with a certain text. For example, if any cell in column O begins with "ES", msg box "Spain Trades"(no action if not). Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this:
Code:
Sub Test()
'Modified 4/24/2018 12:10 PM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "O").End(xlUp).Row
    For i = 1 To Lastrow
        If Left(Cells(i, "O"), 2) = "ES" Then MsgBox "Spain Trades"
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
hi, I'm trying to create a line in my macro to show a msg box if cells in a give range begin with a certain text. For example, if any cell in column O begins with "ES", msg box "Spain Trades"(no action if not). Thanks!
While it will not display a MessageBox, you might want to consider using Conditional Formatting (maybe color cells starting with "ES" red for example) instead of a macro.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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