Tricky excel formula

Pjam

Board Regular
Joined
Jun 4, 2008
Messages
139
i am trying to write code that does the following.

i have a range of data from A1: A5000 once a cell is zero i want all cells below that to be zero as well. Any ideas?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
what will be going into the cell, a Formula? or are you likely to be inputting directly, if its the result of a formula the If already mentioned would need to incirporate that, ie IN A2 something like =IF(A1your formula=0,0,Your formula for A2) or similar. if your hardcoding numbers into the cells then you'll need a VBA solution
 
Upvote 0
Code:
Sub test()
Dim c As Range
For Each c In Range("A1:A5000")
    If c = 0 And c <> "" Then
        c.Resize(5001 - c.Row) = 0
        Exit For
    End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

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