Find and replace within a column

  • Thread starter Thread starter level3
  • Start date Start date
L

level3

Hello,
I tried to use vba to perform find and replace for the first 2 columns
of a few sheets
say the column F1

Sheets(2).Range("F1").Select
Selection.Replace what:=" ", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False

But in the end, all of the cells are processed.
I'd like to know how should I limit the find and replace range
properly?
 
That is...
Range("F:G").Replace what:=" ", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False
(No need to select first)
 
Hi Bob,
Thanks for the reply


I tried many ways including your suggestion and something like this

Sheets(2).Activate
Range("A:B").Select
Selection.Replace what:="_", Replacement:=" ", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,
_
ReplaceFormat:=False

Range("F:G").Select
Selection.Replace what:=" ", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, _
ReplaceFormat:=False

But still, every cells' spaces are converted to underscore.
even though I turned on the screen update and saw the selections were
made correctly
 

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