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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ctrl+F (find) method not working as desired!!

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
I am trying to use the Find (Ctrl+F) method in Excel so that i can work in only a portion of my spreadsheet. I am under the impression that the find function searches every cell so I made a loop that says the following;
find the value AT&T in each cell and replace it with the value of Sprint until the cell with the value "Total" is found, then exit out of the loop. This is how I tried to achieve it, but the loop continues until after the cell with the value of Total in it


Do Until ActiveCell.Value = "Total"
Cells.Find(What:="AT&T", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

ActiveCell.Value = "Sprint"

Loop

I know that there is a replace method but it still does not prevent the loop from continuing infinetely. I would appreciate any help thank you.
 
The find or replace function can be utilised in the following way:

With Worksheets(1).Range("a1:a500")
Set c = .Find("AT&T", lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.value = "Sprint"
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

Straight from excel help file Rgds
Geoff
&quot;Some cause happiness wherever they go; others whenever they go.&quot;
-Oscar Wilde
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top