View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default find replace within sheet or workbook

Not sure where your "Within" comes from. According to help on this subject,
(may vary slightly depending on your version of XL):

"expression.Replace(What, Replacement, LookAt, SearchOrder, MatchCase,
MatchByte, SearchFormat, ReplaceFormat)

expression Required. An expression that returns a Range object.
What Required Variant. The string you want Microsoft Excel to search for.
Replacement Required Variant. The replacement string.
LookAt Optional Variant. Can be one of the following XlLookAt constants:
xlWhole or xlPart....."

So if you want to perform the replace for all WSs in the WB, loop through
the WS collection

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Cells.Replace "a", "b"
Next

NickHK

"mcphc" wrote in message
...
Is there a way to change the search within feild in the replace command

from
"sheet" to "workbook"?

ie something like:

Cells.Replace What:="a", Replacement:="b", Within:=xlSheet

The within option in replace doesn't seem to be covered in VB

Cells.Replace
yet Cells.Replace is effected by what ever the Within option is set to

using
the normal find/replace command in excel.

The only other idea I have come up with is using sendkeys but sendkeys may
not be very robust.