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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

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