To auto-populate the rest of the data by looking at previous data cell (pivot to columnised data)

bluue s
bluue s used Ask the Experts™
on
To auto-populate the rest of the data by looking at previous data cell (pivot to columnised data).

Worksheets:
Pivot = summarised data created from a pivot
interim = copy  the summarised data into columnised data for further analysis
Result= what i want is to fill in the blanks (auto populate as it is very tedious and time consuming to copy the data from the top) with the previous headers to get a columnised data for further analysis.

See attached for details..
AutoPopulate-Data-from-summarised-d.xlsx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
If Pivot Sheet in the sample file actually contains an actual Pivot Table, the following code will copy the data from the Pivot Table from the Pivot Sheet into the Interim Sheet and fill all the blanks cells.

Note: The code will not work on the sample file as there is no actual Pivot Table on the Pivot Sheet.

See if it works for you.

Sub UpdateInterimSheet()
Dim wsPivot As Worksheet
Dim dws As Worksheet
Dim pt As PivotTable
Dim lr As Long

Application.ScreenUpdating = False

Set wsPivot = Sheets("Pivot")
Set dws = Sheets("Interim")
dws.Cells.Clear

Set pt = wsPivot.PivotTables(1)
pt.TableRange1.Copy dws.Range("A1")
lr = dws.Range("A1").CurrentRegion.Rows.Count
On Error Resume Next
dws.Range("A2:B" & lr).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
dws.Range("A2:B" & lr).Value = dws.Range("A2:B" & lr).Value
On Error GoTo 0
Application.ScreenUpdating = True
End Sub

Open in new window

Author

Commented:
yes it works but it doesn't work if i inserted another rows

in this case initially i had
Months      Interval      Date      Time      No of Lines

but if i have
Months      weeks  Interval      Date      Time      No of Lines

then only Months and Weeks (ie the first 2 column are populated and interval is being left out)

Is it possible to do a generic macro where it will auto-populate all the blank fields for any number of rows inserted in pivot?

Thanks.
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
Okay try this and see if that works for you.

Sub UpdateInterimSheet()
Dim wsPivot As Worksheet
Dim dws As Worksheet
Dim pt As PivotTable
Dim lr As Long, lc As Long

Application.ScreenUpdating = False

Set wsPivot = Sheets("Pivot")
Set dws = Sheets("Interim")
dws.Cells.Clear

Set pt = wsPivot.PivotTables(1)
pt.TableRange1.Copy dws.Range("A1")
lr = dws.Range("A1").CurrentRegion.Rows.Count
lc = dws.Range("A1").CurrentRegion.Columns.Count
On Error Resume Next
dws.Range(dws.Cells(2, 1), dws.Cells(lr, lc - 1)).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
dws.Range(dws.Cells(2, 1), dws.Cells(lr, lc - 1)).Value = dws.Range(dws.Cells(2, 1), dws.Cells(lr, lc)).Value
On Error GoTo 0
Application.ScreenUpdating = True
End Sub

Open in new window

Author

Commented:
Very prompt, good !
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
Thanks for the feedback! ☺️

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial