Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Text Excel Macro

Status
Not open for further replies.

JustATheory

IS-IT--Management
Feb 27, 2003
115
US
Greetings,

I need to write a macro that will search a column of cells in that have about two sentences each with a word (Hello) embeded somewhere with in that text, identify which cells have the text and place a mark ("X") in the cell next to it and continue searching until the activecell = "". Not every cell has this text. It's similar to the simple "Find" function, but I need to identify each cell that contains this text.

Any help is greatly appreciated.

Thanks,
Andy
 
Hi there,

You can something like this ...

Code:
Sub MarkAll()
    Dim c As Range, rngLoop As Range
    Set rngLoop = Sheets("Sheet1").Range("A1:A100")
    For Each c In rngLoop
        If InStr(1, UCase(c.Value), "HELLO") <> 0 Then
            c.Offset(0, 1).Value = "X"
        End If
    Next c
End Sub

Change out the sheet name and range for your specifics. This does not check for case sensitivity; if that matters to you, remove the surrounding UCase() and change the "HELLO" to the case sensitivity you desire.

Also, it assumes "cell next to it" means one cell to the right.

HTH

-----------
Regards,
Zack Barresse
 
straight from the help files:
Code:
With Worksheets(1).Range("a1:a100")
    Set c = .Find("HELLO", lookin:=xlValues, lookat:=xlpart)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            c.offset(0,1).value = "X"
            Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Thanks to both firefytr and xlbo, for some great code. Both code sets work well and accomplised my task.

Thanks,
Andy
 
For large data sets, Geoff's code will run much faster.

I thought about throwing one of those routine's together, guess I just got lazy. :?

-----------
Regards,
Zack Barresse
 
possibly - I just remembered that the FindNext example in help is very good and easily modded !

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top