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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,109,368
Messages
5,528,274
Members
409,813
Latest member
robyrux

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top