VBA, find and replace

A

Aaron

I am having a hard time trying to write a macro that does a find and replace
function on the workbook and then does another one on just a spreadsheet.
I've been googling vba code and haven't found a result. When I record the
macro myself, the code continues to return the same despite the function
running on a within a workbook and then just within a spreadsheet...

On the workbook...
Cells.Replace What:="Projections!n3", Replacement:="Projections!$n$3", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:= _
False, ReplaceFormat:=False

On the worksheet...
Sheets("Projections").Select
Cells.Replace What:="n2=", Replacement:="$n$2=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Any ideas?
 
D

Dave Peterson

You could loop through the worksheets:

dim wks as worksheet
for each wks in activeworkbook.worksheets
wks.Cells.Replace What:="n2=", Replacement:="$n$2=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
next wks
 

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

Top