MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

seeking the word or integer word

  Asked By: Sean    Date: Aug 19    Category: MS Office    Views: 1807

how can I find the word or the number on a activated sheet via using VBA?
Besides, after the word or the number is found, how can I learn column number
and row number of found cell?



2 Answers Found

Answer #1    Answered By: Felicia Hill     Answered On: Aug 19

Returning the row  and column number  is easy.

There are several ways to "find" what you're looking for.
The best way depends on what it is you're trying to find.
Are you looking for a word  within a string?
a number within a string?
Or do you want to know all cells that are EQUAL to your designated string?
That is: If you're looking for "Jack", do you want ONLY cells that contain
"Jack", or do you want to include "Jacks", "Jackson", "Billy Jack", "Yukon
"Cactus Jack", "Kojack" ??

Answer #2    Answered By: Corinne Rogers     Answered On: Aug 19

Try this:

Sub test()
Dim FirstAddress, c As Range
With Worksheets(1).Range("a1:a500") 'Searches Column A, rows 1-500
Set c = .Find("2", LookIn:=xlValues, Lookat:=xlWhole) '(looks for
If Not c Is Nothing Then
FirstAddress = c.Address
MsgBox c.Address & ": " & c.Value & " Row: " & c.Row & "
Col: " & c.Column
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
End With

End Sub

Didn't find what you were looking for? Find more on seeking the word or integer word Or get search suggestion and latest updates.