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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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