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>
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,077
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
46,077
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
46,077
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
46,077
Office Version
  1. 365
Platform
  1. Windows
You're welcome
 

Watch MrExcel Video

Forum statistics

Threads
1,108,609
Messages
5,523,885
Members
409,542
Latest member
Shezz01

This Week's Hot Topics

Top