problem with replace (VB)

  • Thread starter Thread starter Sieto Verver
  • Start date Start date
S

Sieto Verver

Dear all,
Sorry to bother you with this question but if anybody can provide help, it
would be much appreciated.
As a part of a macro code I want to replace values in column E. As the
number of records differs by sheet, I want to select the whole column and
perform the replace action.
With the code below this text, the search and replace is ok, except that the
action is performed within the whole sheet. What is wrong with the
selection?
Hope it is clear.

Thanks,
Sieto

Sub replace()
Columns("E:E").Select
Range("E2").Activate
Selection.Replace What:="AT", Replacement:="anything", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False
End Sub
 
try this slight modification

with columns("e:e")
..replace what:="AT",replacement:="anything"
end with

then I thin replcement wil be done only in column E
============
 
Thanks R. That did the trick, although I don't understand why the other
won;t work, but that's fine for now!

Sieto
 
While I advise the suggested correction as better coding practice, for
interest, your original code ran fine for me.
 

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

Back
Top