Formula or macro to retrieve cell above to replace zero

GreyFox8991

New Member
Joined
Jul 20, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
Greetings excel community,

I have some cells that contain a zero and I would like to replace the zero value with the value from the preceding row (the cell above). I saw a formula online which is as follows:=INDIRECT(ADDRESS(ROW()-1|COLUMN())). However, I would have to copy and paste this value multiple times in order to replace the zero values in the cells. Would anyone have a suggestion or an addition to the formula that might extrapolate this to other cells? A3 contains the formula i referenced earlier. This formula would have to be pasted into the next cell to replace the zero in order to retrieve the value from the cell above. Any insight would be greatly appreciated.

Book2
A
223435357
323435357
423471373
50
60
723474577
80
923471728
1023476975
110
1223447346
1323447460
140
Sheet1
Cell Formulas
RangeFormula
A3A3=INDIRECT(ADDRESS(ROW()-1,COLUMN()))
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this on a copy of your Workbook
VBA Code:
Public Sub ReplaceZero()
Dim lRow As Long, rng As Range, cell As Range
lRow = Columns(1).Rows.End(xlDown).Row
Set rng = Range("A1:A" & lRow)
For Each cell In rng
    If cell.Value = 0 Then cell.Value = cell.Offset(-1, 0).Value
Next cell
End Sub
 
Upvote 0
Solution
You could also do this fairly quickly manually as follows
  1. Select the range (or whole column)
  2. Ctrl+F to invoke the Find dialog
  3. Find what: 0 and set 'Match entire cell contents' then click 'Find All'
  4. Immediately type Ctrl+A
  5. Close the Find dialog
  6. With all the 0 cells still selected, Press the = key then the up arrow key then Ctrl+Enter
  7. Optional: If you want to replace the formulas with those values select the whole range/column again and do a Copy -> PasteSpecial (Values)
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

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