filling empty cells below with cell above

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hey guys, So i have a pivot table, and i need to copy it to another page to run calculations on it and what not. when i copy it over, there are a lot of blank cells under the cells with content, since it was merged in a pivot table. I'm trying to create a macro which would automatically fill the empty cells below it with the cell value above it. How would I go about doing that?

here's an example table

some namename
Name2
some other namename 3
name 4

<tbody>
</tbody>


here's how what I'm trying to get.

Some Namename
Some Namename
Some Namename
Some Namename 2
Some Other Namename 3
Some Other Namename 3
Some Other Namename 4
Some Other Namename 4

<tbody>
</tbody>
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You can repeat the labels in the pivot table. Right click the field in question-Field Settings-Layout and Print then check Repeat item labels. Is that what you mean?
 
Upvote 0
So the table im messing with is not a pivot table. I created a copy of just the text from my pivot table, and set it as a range. I'm trying to get a macro to automatically repeat labels. on my table.
 
Upvote 0
Possibly (with the layout as per the below)...

Code:
Sub FillCell2()
    With Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row + 1)
        .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
        .Value = .Value
    End With

    With Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row + 1)
        .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
        .Value = .Value
    End With
End Sub

or

Code:
Sub FillCell2()
    Dim fCell As Range
    On Error Resume Next

    For Each fCell In Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row + 1). _
        SpecialCells(xlCellTypeBlanks).Areas
        fCell.Value = fCell(1).Offset(-1).Value
    Next
    
    On Error GoTo 0

    On Error Resume Next
    
    For Each fCell In Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row + 1). _
        SpecialCells(xlCellTypeBlanks).Areas
        fCell.Value = fCell(1).Offset(-1).Value
    Next

    On Error GoTo 0
End Sub


Excel 2010
AB
2some namename
3
4
5Name2
6some other namename 3
7
8name 4
9
Sheet4
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,958
Messages
6,127,937
Members
449,412
Latest member
sdescharme

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