Delete

C

chrisnsmith

Recorded this macro, but I only want it to work in column C from row 6
downward.
What do I need to add?

Cells.Replace What:="O", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceForm
 
D

Dave Peterson

With activesheet
With .range("c6:c" & .rows.count)
.cells.replace ....
end with
end with

Did you really mean xlpart, not xlwhole?
 
S

Sheeloo

You need to first select the range then run the macro below;
Change from your macro = replaces Cells (which means all cells on the
worksheet with Selection)

If you do not want to select the range before running the macro then remove
the ' before the line
' Range("F6:F50").Select
and change 50 to whatever you want...

Use
Sub Macro1()
' Range("F6:F50").Select
Selection.Replace What:="O", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
 
C

chrisnsmith

That works if there are O's in column C, but I should have asked for
something that will function just as well when there are no O's in column C.
Can you help?
 
C

chrisnsmith

I'm not sure I understand what you mean. I did test the codes that both you
and Sheloo posted. I tried eliminating lines that I thought might be causing
a problem when there were no O's in column C, but I'm a novice at this and am
not sure what lines I should be eliminating. All I know is that when I try
to run the code, and there are no O's to replace I get a highlight in the VB
module.
 
C

chrisnsmith

Forget it. Used the replace command instead.

Dave Peterson said:
With activesheet
With .range("c6:c" & .rows.count)
.cells.replace ....
end with
end with

Did you really mean xlpart, not xlwhole?
 

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