Paste cell above if blank

carlosjcabral

New Member
Joined
Dec 30, 2005
Messages
28
New at this, not sure what I did wrong. All I want it to do is look at the cell and if it is blank then paste the value in the cell above it. Then reapeat this until the end of the page.


dim rz As Long, z As Long

rz = Cells(Rows.Count, 4).End(xlUp).Row
For z = rz To 1 Step -1

If Cells(z, 2).Value = "" Then Value = Cells(z - 1, 2).Value

Next z
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Rich (BB code):
dim rz As Long, z As Long

rz = Cells(Rows.Count, 4).End(xlUp).Row
For z = rz To 1 Step -1

If Cells(z, 2).Value = "" Then Cells(z, 2).Value = Cells(z - 1, 2).Value

Next z
<!-- / message -->
 
Upvote 0
kpark91, You'll get error if B1 is blank.
 
Upvote 0
Ahh.. I didn't notice that.
Thanks Sektor.

Rich (BB code):
dim rz As Long, z As Long

rz = Cells(Rows.Count, 4).End(xlUp).Row
For z = rz To 2 Step -1

If Cells(z, 2).Value = "" Then Cells(z, 2).Value = Cells(z - 1, 2).Value

Next z
<!-- / message -->
 
Upvote 0
Are you sure that you define last row by D column?
 
Upvote 0
I changed the 1 to a 2 and I stop getting the error, but its looks like it only copys and paste once for each value. I want it to do each row on the sheet like the first column. Thanks for your help on this.


40012 40012
40012 40012
40012
40012
40013 40013
40013 40013
40013
40013


dim rz As Long, z As Long

rz = Cells(Rows.Count, 4).End(xlUp).Row
For z = rz To <b>2</b> Step -1

If Cells(z, 2).Value = "" Then Cells(z, 2).Value = Cells(z - 1, 2).Value

Next z
 
Upvote 0
but its looks like it only copys and paste once for each value. I want it to do each row on the sheet like the first column.
Can you explain in more detail what you mean by that? Do you mean each column?

For column D, see if this does what you want. It doesn't require checking every cell one at a time. Test in a copy of your workbook.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> FillBlanks()<br>    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Range("D2", Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks)<br>        .FormulaR1C1 = "=R[-1]C"<br>        .Value = .Value<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
I hope this helps my excel sheet looks like the on on the right with all the blanks. I want it to go down the sheet and if the cell is blank then paste the cell above it. like the left side example. One thing to note... the data is in column B to not D so I sure I defined it incorrectly. I hope the helps. Thanks.



11 11
11
11
11
11
33 33
33
33
33
33
33
22 22
22
22
22
22
22
44 44
44
44
44
44
44
end of page
 
Upvote 0
How do you identify whether it's the end of page?

Rich (BB code):
dim rz As Long, z As Long

rz = Cells(Rows.Count, 2).End(xlUp).Row
For z = 2 To rz
    If Cells(z, 2).Value = "" Then Cells(z, 2).Value = Cells(z - 1, 2).Value
Next z
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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