Recognising first word in cell

aa2000

Board Regular
Joined
Aug 3, 2011
Messages
87
Hi guys

In a macro I'm working on, I wish to run a procedure if the first word in a cell in that column matches a certain word.

For example the text in a cell in the column reads

"Experiment 45 8"

Where the numbers vary with each one.
Currently I have written this:

Code:
If Cell(a, 1).Value = "EXPERIMENT" & "*" Then ...

However this does not work, so what should I change?

Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Will this word occur multiple times?

Are you currently going through each cell of data in the first column? If so, you could be using .find to go straight to the cells

Code:
Sub findRows()
    With Columns(1)
        Set f = .Find(what:="Experiment*", lookat:=xlWhole)
        If Not f Is Nothing Then
            fa = f.Address
            Do
                'insert code here:  if you need to know the row no. you can use f.row
                Set f = .FindNext(f)
            Loop Until f.Address = fa
        End If
    End With
End Sub
This will loop through all cells in column 1 where "Experiment" is the first text, stopping when it reaches the same cell it started with.
 
Upvote 0
or to use your current syntax:

Code:
If Cell(a, 1).Value like "EXPERIMENT*" Then ...
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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