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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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
This worked for me;

Code:
    For Each c In Range("O:O")
        If Left(c.Value, 2) = "ES" Then
            MsgBox ("Spain Trades")
        End If
    Next
 
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,215,493
Messages
6,125,134
Members
449,206
Latest member
burgsrus

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