Copy filled cells in a column to empty cells below - until the next filled cell occures - and so on

TROWKRO

New Member
Joined
Mar 20, 2019
Messages
5
Hi. I have a table with a column A containing filled cells and empty cells. I would like to create a VBA that copies the filled cells to the empty cells below, and when a new cell value occures, this will be copied to the next cells below etc. until there are no more values in column B. Would this be possible?

Thanks at advance.


[TABLE="width: 500"]
<tbody>[TR]
[TD]Column A[/TD]
[TD]Column B[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "10"[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "25"[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "25"[/TD]
[TD]67[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "25"[/TD]
[TD]77[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "25"[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]30[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "30"[/TD]
[TD]90[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "30"[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "30"[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "30"[/TD]
[TD]60[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "30"[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]empty - should be filled with "30"[/TD]
[TD]2[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
How about
Code:
Sub Trowkro()
   With Range("A2", Range("B" & Rows.Count).End(xlUp))
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Hi again. Effectively, there is a little problem. The column B should not be filled the same way as with the column A. Column B should not be touched at all.
The proposed code fills the column B the same way as the column A if there is an empty cell or more. Could we tweak the code a little to avoid this?
 
Upvote 0
Oops I missed a bit out, it should be
Code:
Sub Trowkro()
   With Range("A2", Range("B" & Rows.Count).End(xlUp)[COLOR=#ff0000].Offset(, -1)[/COLOR])
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
      .Value = .Value
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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