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

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
bluue sAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
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

0
bluue sAuthor 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.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bluue sAuthor Commented:
Very prompt, good !
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Thanks for the feedback! ☺️
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.