ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search and Replace (https://www.excelbanter.com/excel-programming/433335-search-replace.html)

Muttley

Search and Replace
 
I'm wanting to search and replace a worksheet, but rather than replace with a
set bit of text, I want to replace it with something defined within my VBA
code:

Cells.Replace What:="Annuity L_All", Replacement:=file_noxls, LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False

The "replace" text is definitely there, but when I run the code, it doesn't
repalce anything... can anyone help / spot the obvious error?

Thanks! :)

Rick Rothstein

Search and Replace
 
Your code snippet works for me. Just out of curiosity, is the worksheet that
contains your "Annuity L_All" text the ActiveWorksheet (the Cells property
is not referencing any particular worksheet, so it will refer to the
ActiveSheet by default)?

--
Rick (MVP - Excel)


"Muttley" wrote in message
...
I'm wanting to search and replace a worksheet, but rather than replace
with a
set bit of text, I want to replace it with something defined within my VBA
code:

Cells.Replace What:="Annuity L_All", Replacement:=file_noxls, LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False

The "replace" text is definitely there, but when I run the code, it
doesn't
repalce anything... can anyone help / spot the obvious error?

Thanks! :)



Jacob Skaria

Search and Replace
 
Refers ActiveSheet..

Dim file_noxls As String
file_noxls = "replaced"
Cells.Replace What:="Annuity L_All", _
Replacement:=file_noxls, SearchOrder:=xlByRows

If this post helps click Yes
---------------
Jacob Skaria


"Muttley" wrote:

I'm wanting to search and replace a worksheet, but rather than replace with a
set bit of text, I want to replace it with something defined within my VBA
code:

Cells.Replace What:="Annuity L_All", Replacement:=file_noxls, LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False

The "replace" text is definitely there, but when I run the code, it doesn't
repalce anything... can anyone help / spot the obvious error?

Thanks! :)



All times are GMT +1. The time now is 03:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com