Formula To Delete Certain Cells ?????

CARBOB

Well-known Member
Joined
Jun 6, 2005
Messages
1,870
I want to delete the all cells from C24:D4469 that has a zero in the Col D D, but the cell in Col C has to be deleted also. Ex C24:D30, delete, skip C31:D32; delete C33:D53, Etc. Can this be done with a formula? Thanks for all suggestions.
FL CASH 3 DIGITS SKIPS.xls
CDEF
24EOELHLIOI000#NUM!
25OEELHHIOO000#NUM!
26EEOHHHIIO000#NUM!
27EEOHHLOOI000#NUM!
28EOEHHHIOI000#NUM!
29OEEHHLOOI000#NUM!
30OOEHHLOOI000#NUM!
31EOOHHLOOI0224542454
32EEEHHHOII031016800.5
33EEEHLLOOI000#NUM!
34EOEHHHIOO000#NUM!
35EOEHLHIII000#NUM!
36EOEHLLOII000#NUM!
37OOEHLLOOI000#NUM!
38OEOLHLIOI000#NUM!
39EOOHHHOOO000#NUM!
40EOOHLHIIO000#NUM!
41OOOLLLOOI000#NUM!
42OOOLLHIIO000#NUM!
43OOOHLLOIO000#NUM!
44EEEHHHOOO000#NUM!
45EEOHLLOII000#NUM!
ODDEVEN-HIGHLOW-INOUT SKIPS (2)
 
If you do not want the rows deleted, then this code will clear Columns C and D when column D is zero.
Code:
Sub DeleteZeroCells()
Dim CheckRange As Range, c As Range
    Set CheckRange = Range("D1:D" & _
    Range("D65536").End(xlUp).Row - 2)
    For Each c In CheckRange
        If c.Value = 0 Then
        c.Value = ""
        c.Offset(0, -1).Value = ""
        End If
    Next c
End Sub

HotPepper,
Thanks for pointing out my error in my entire row deletion code. You are correct, you have to work it from the bottom up so it won't skip rows.
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Does this work for you?

Code:
Sub DeleteZeros()
Dim x As Long, y As Long
x = Range("D" & Rows.Count).End(xlUp).Row
For y = x To 24 Step -1
    If Range("D" & y) = 0 Then Range("C" & y).Resize(, 2).Delete xlShiftUp
Next y
End Sub

Hotpepper, thank you, it appears to have worked. Took 8 minutes to run. Took me an hour to do 200 rows by hand.
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,265
Members
449,219
Latest member
daynle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top