Formula or macro to itemise summarised results

saraapple

Board Regular
Joined
Feb 3, 2020
Messages
165
Office Version
  1. 2010
Platform
  1. Windows
I am hoping someone could advise me on the below - or just any ideas that could help.
I want to do the opposite of a pivot table of sorts, my data is summarised and I need to break it down into singles.
The reason I need to break it into singles, is I need to plan loads of say 40 with the potential for each load to have a remainder - hence the need for singles to accurately calculate.

I already have the macro to split the data from singles (I think with a few amendments) but I need to get to singles to test it works!

Here is what I have and what I want:

New Wave File Template Aug 2021.xlsm
ABCDEFGHI
1PriorityStore NumberStore NameSum of Pallet TotalPriorityStore NumberStore NameSum of Pallet Total
21114Jersey21114Jersey1
33865Broadstairs41114Jersey1
44800Canterbury113865Broadstairs1
55265Ashford63865Broadstairs1
6233865Broadstairs1
73865Broadstairs1
84800Canterbury1
94800Canterbury1
104800Canterbury1
114800Canterbury1
124800Canterbury1
134800Canterbury1
144800Canterbury1
154800Canterbury1
164800Canterbury1
174800Canterbury1
184800Canterbury1
195265Ashford1
205265Ashford1
215265Ashford1
225265Ashford1
235265Ashford1
245265Ashford1
2523
Sheet6
Cell Formulas
RangeFormula
A1:D5A1='Stoke 1 Pallets'!F6
D6D6=SUM(D2:D5)
I25I25=SUM(I2:I24)


Is there a function in excel to reverse a pivot table?

Thank you for your time
Sara
 
Sub Macro22()
'
' Macro22 Macro
'Sub k1()
lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
k = 0
For i = 2 To lastrow
For j = 1 To Worksheets("Sheet2").Cells(i, 4)
k = k + 1
Worksheets("Sheet1").Cells(k,6)=Worksheets("Sheet1".Cells(i,1))
Worksheets("Sheet1").Cells(k,7)=Worksheets("Sheet1".Cells(i,2))
Worksheets("Sheet1").Cells(k,8)=Worksheets("Sheet1".Cells(i,3))
Next j
Next i
End Sub '

This is what I now have but still:

1629214730265.png

These error messages are my nightmare, I never understand what they mean?!?
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Using the example you showed in post #5

Assuming data in A:B

Pasta1
ABCDEF
1NamesTotalListPalletsHelper
2Sara3Sara10
3Marcelo5Sara13
48Sara18
5Marcelo1
6Marcelo1
7Marcelo1
8Marcelo1
9Marcelo1
10  
Plan5
Cell Formulas
RangeFormula
D2:D10D2=IF(ROWS(D$2:D2)>B$4,"",INDEX(A$2:A$3,MATCH(ROWS(D$2:D2)-1,F$2:F$4)))
E2:E10E2=IF(D2="","",--(D2<>""))
F2:F4F2=SUM(B$1:B1)
B4B4=SUM(B2:B3)


M.
You are right! I am just trying to tweak this to cover my actual data but this will do the job.
My only concern is handing this over to none excel people, which is why I am also looking at the possibility of a macro (I need as little operator involvement as possible) Thank you so much, as soon as I have this working at I can look at protection options and take things from there :)
 
Upvote 0
I am also looking at the possibility of a macro (I need as little operator involvement as possible)

Try

VBA Code:
Sub aTest()
    'Assumes data in columns A:D; headers in row 1
    'Results in columns F:I
    Dim vData As Variant, vResult As Variant
    Dim lNumRows As Long, i As Long, j As Long, lLin As Long
   
    vData = Range("A2:D" & Cells(Rows.Count, "A").End(xlUp).Row)
    lNumRows = Application.Sum(Application.Index(vData, 0, 4))
    vResult = Range("F2").Resize(lNumRows, 4)
       
    For i = 1 To UBound(vData, 1)
        For j = 1 To vData(i, 4)
            lLin = lLin + 1
            vResult(lLin, 1) = vData(i, 1)
            vResult(lLin, 2) = vData(i, 2)
            vResult(lLin, 3) = vData(i, 3)
            vResult(lLin, 4) = 1
        Next j
    Next i
    Range("F1:I1").Value = Range("A1:D1").Value
    Range("F2").Resize(lNumRows, 4) = vResult
    Columns("F:I").AutoFit
End Sub

M.
 
Upvote 0
Solution
Try

VBA Code:
Sub aTest()
    'Assumes data in columns A:D; headers in row 1
    'Results in columns F:I
    Dim vData As Variant, vResult As Variant
    Dim lNumRows As Long, i As Long, j As Long, lLin As Long
  
    vData = Range("A2:D" & Cells(Rows.Count, "A").End(xlUp).Row)
    lNumRows = Application.Sum(Application.Index(vData, 0, 4))
    vResult = Range("F2").Resize(lNumRows, 4)
      
    For i = 1 To UBound(vData, 1)
        For j = 1 To vData(i, 4)
            lLin = lLin + 1
            vResult(lLin, 1) = vData(i, 1)
            vResult(lLin, 2) = vData(i, 2)
            vResult(lLin, 3) = vData(i, 3)
            vResult(lLin, 4) = 1
        Next j
    Next i
    Range("F1:I1").Value = Range("A1:D1").Value
    Range("F2").Resize(lNumRows, 4) = vResult
    Columns("F:I").AutoFit
End Sub

M.
This is fantastic THANK YOU!
The formula way works great to and I have a few other uses for it.
I am going to analyze your code now, figure out exactly how it works thank you again this is a HUGE help to me :)
 
Upvote 0
Sub Macro22()
'
' Macro22 Macro
'Sub k1()
lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
k = 0
For i = 2 To lastrow
For j = 1 To Worksheets("Sheet2").Cells(i, 4)
k = k + 1
Worksheets("Sheet1").Cells(k,6)=Worksheets("Sheet1".Cells(i,1))
Worksheets("Sheet1").Cells(k,7)=Worksheets("Sheet1".Cells(i,2))
Worksheets("Sheet1").Cells(k,8)=Worksheets("Sheet1".Cells(i,3))
Next j
Next i
End Sub '

This is what I now have but still:

View attachment 45043
These error messages are my nightmare, I never understand what they mean?!?
Looks like you've sorted it now.
Just for solution purposes I put a bracket in the wrong place

Code:
Worksheets("Sheet1").Cells(k,6)=Worksheets("Sheet1").Cells(i,1)
Worksheets("Sheet1").Cells(k,7)=Worksheets("Sheet1").Cells(i,2)
Worksheets("Sheet1").Cells(k,8)=Worksheets("Sheet1").Cells(i,3)

That'll teach me to post untested code
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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