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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,214,985
Messages
6,122,603
Members
449,089
Latest member
Motoracer88

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