Search for text string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi! I have a macro that searches through a list of data using objects. I want
to see if a cell contains a certain value and if so then do something. The
cell can contain eg: AUSTRIA GVB 2012 JUL 5.0%. However, I am just interested
in AUSTRIA. The rest does not matter. I have a list of the words I am looking
for. Basically all I want to know is how can I search a cell for a certain
value? Thanks alot!!
 
Hello Arne
Dim Rg As Range
With Range("A1:E1")
Set Rg = .Find("AUSTRIA", LookIn:=xlValues, lookat:=xlPart)
If Not Rg Is Nothing Then
MsgBox "Value found in " & Rg.Address
End If
End With

See VBA help for further info on Find method.

HTH
Cordially
Pascal
 
The code below will return a message mox saying "yup" of A1 contains
AUSTRIA anywhere within it's text.
Sub try()
If InStr(1, Cells(1,1), "AUSTRIA", 1) _
Then MsgBox "yup"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top