Macro to delete 0

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to record something along the lines of

If Active.Cell = 0, then delete all 0s in column C - Y (for that same row only

The active cell would always be in column b
 
With Activecell
If .Value = 0 Then
Range("C" & .Row & ":Y" & .Row"").Replace What:="0", _
Replacement:="", _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False
End If
End WIth


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
When I entered this into the macro, from the word
Range ("C"... through.... MatchCase:=False
shows up in red and the "" after the second Row is highlighted.
 
Sorry, some extra ""

With ActiveCell
If .Value = 0 Then
Range("C" & .Row & ":Y" & .Row).Replace What:="0", _
Replacement:="", _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False
End If
End With


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
If I wanted to be able to select several cells, could ActiveCell be replaced with SelectedCells or something along the lines
----- Bob Phillips wrote: ----


With Activecel
If .Value = 0 The
Range("C" & .Row & ":Y" & .Row"").Replace What:="0",
Replacement:="",
LookAt:=xlWhole,
SearchOrder:=xlByRows,
MatchCase:=Fals
End I
End WIt


--

HT

Bob Phillip
... looking out across Poole Harbour to the Purbeck
(remove nothere from the email address if mailing direct
 
No, you would need to lop through them, but make sure only the cells in
column B are selected

For Each cell In Selection
If cell.Value = 0 Then
Range("C" & cell.Row & ":Y" & cell.Row"").Replace
What:="0", _
Replacement:="", _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False
End If
Next cell


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Hargrove said:
If I wanted to be able to select several cells, could ActiveCell be
replaced with SelectedCells or something along the lines?
 
Hi
try

dim rng as range
dim cell as range
set rng = selection
for each cell in rng
With cell
If .Value = 0 Then
Range("C" & .Row & ":Y" & .Row).Replace What:="0", _
Replacement:="", _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False
End If
End With
next
 
oops that mistake again

For Each cell In Selection
If cell.Value = 0 Then
Range("C" & cell.Row & ":Y" & cell.Row).Replace _
What:="0", _
Replacement:="", _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False
End If
Next cell


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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