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

Excel Replace

Status
Not open for further replies.

Leighton21

Technical User
Dec 17, 2001
83
AU
Hi Guys,

I am using code similar to the following

For Each WS In Worksheets
WS.Cells.Replace What:=Search, Replacement:=Replacement, _
LookAt:=xlPart, MatchCase:=False
Next

to try to replace values in a sheet. My question is can you reference the row number of the cell that is currently being replaced i.e.

Say if I was on row 6 and I wanted to replace and column B had the Value B[Row] I would like to replace Row with the actual rownumber.

I can do it with a loop but the replace seems quicker

Cheers
 



Leighton,

Yes, REPLACE is quicker...quicker to give you incorrect results.

Use your loop.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
to do what you want, you would need to use Findnext and a loop - bit more efficient than a pure loop through all records but a loop nonetheless...

There is a vey good example of using findnext in the VBA help files

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