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.


Column AColumn B
102
empty - should be filled with "10"3
254
empty - should be filled with "25"45
empty - should be filled with "25"67
empty - should be filled with "25"77
empty - should be filled with "25"3
300
empty - should be filled with "30"90
empty - should be filled with "30"12
empty - should be filled with "30"45
empty - should be filled with "30"60
empty - should be filled with "30"1
empty - should be filled with "30"2

<tbody>
</tbody>
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

TROWKRO

New Member
Joined
Mar 20, 2019
Messages
5

ADVERTISEMENT

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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,043
Office Version
  1. 365
Platform
  1. Windows
You're welcome
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,592
Messages
5,832,630
Members
430,149
Latest member
amitk1

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
Top