How to fill in blank rows in mutiple columns?

Ann99

New Member
Joined
Sep 14, 2009
Messages
27
Hi,
Last week I found a thread with VBA that enabled blank rows below a value to be filled in with that value until the next value, then the rows below were filled in with the second value and so on.

It worked in Column A only. How can this work in all columns that need the same treatment, A, B, C, etc.?

This is the VBA from the thread that I used:

Sub FillInFromRowAbove1()

With Range("A2", Cells(Rows.Count, "B").End(xlUp).Offset(, -1))
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=r[-1]c"
.Value = .Value
End With
End Sub

Thanks, Ann
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub FillInFromRowAbove1()
Dim LR As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("A2:C" & LR)
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
End With
End Sub
 

Myproblem

Board Regular
Joined
May 24, 2010
Messages
198
Try

Code:
Sub FillInFromRowAbove1()
Dim LR As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("A2:C" & LR)
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
End With
End Sub

it is great macro, i would like to ask how would be this macro should be modife in the way that with message box it ask you which column is the the last right column (i want this vba code to make it in private.xls and it would be great stuff making it)
thx in advance
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650

ADVERTISEMENT

Maybe this - LC finds the last column.

Code:
Sub FillInFromRowAbove1()
Dim LR As Long, LC As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
With Range(Cells(2, 1), Cells(LR, LC))
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
End With
End Sub
 

Myproblem

Board Regular
Joined
May 24, 2010
Messages
198
thx man,
i just modify it to be placed into module so it can be actived in any active sheet (due need to be called from private), thx again my timesaver:
Sub FillInFromRowAbove1()
With ActiveSheet
Dim LR As Long, LC As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
With Range(Cells(2, 1), Cells(LR, LC))
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
.Value = .Value
End With
End With
End Sub
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Then it should be

Code:
Sub FillInFromRowAbove1()
Dim LR As Long, LC As Long
With ActiveSheet
    LR = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    LC = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
    With .Range(.Cells(2, 1), .Cells(LR, LC))
        .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
        .Value = .Value
    End With
End With
End Sub
 
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,164,303
Messages
5,836,520
Members
430,437
Latest member
Emilycr

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