multiple columns in a pivot table

nparsons75

Well-known Member
Joined
Sep 23, 2013
Messages
1,254
Office Version
  1. 2016
Hi,

I have a table of contents that I need to create a pivot table for. The issue is that for each row of data in the table i need to record a quantity against multiple part types. Please see example table below.

PARTQTYPARTQTYPARTQTYPARTQTYPARTQTY
00110002120031
0049005600240012

<tbody>
</tbody>







So, from a pivot table I need to be able to find the overall total quantity per each part type. The result of the pivot table will be hopefully like this.

PARTQTY
00112
00216
0031
0049
0056
0060
0070

<tbody>
</tbody>


Really hope this is possible, thanks in advance for any help.
 
Hi, thanks for the numbers, I will try again in the morning as I am away from my work PC. How will the function (macro) work, how is it activated? Thanks,
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi, I changed the numbers but still get an error. I am getting 'script out of range'. for the line below.

a(Sum) = Cells(j, k)
 
Upvote 0
Sub Macro1()
Dim a(100000), b(100000)
For j = 2 To 10000
For k = 65 To 83 Step 2
If Cells(j, k) <> "" Then GoTo 20 Else GoTo 100
20 Sum = Sum + 1
a(Sum) = Cells(j, k)
b(Sum) = Cells(j, k + 1)
100 Next k
Next j
For Z = 2 To 2 + Sum
tot = tot + 1
Cells(Z, 1) = a(tot)
Cells(Z, 2) = b(tot)
Next Z
End Sub

because you have 10000 rows the dim statements need to be increased
also you had dim statement on same line as macro name

copy this exactly
to run macro tools macro, select it, run
you must be running it to get that error message
 
Upvote 0
Hi,

Yes I run it but from within the VBA editor. I assume I would have to create a button for this.

The 10000 rows is a number I gave as the table is continually growing, Im not sure how big it will end up so assume 10000. Currently at 4381. Is there a way to tell it to look to the last row?

I just copied as you said and run the macro, this time without error, thanks. (it did take while to run, maybe a minute or two).

Once the macro had run, I did not see anything, where would the results go.

Again, apologies for my lack of understanding I really do appreciate your patience and help.

Also, how does it know what sheet to work with.

UPDATED

After running a second time (changed the 100000 to 10000) it run very quickly. Must be nearly there now...
 
Last edited:
Upvote 0
This is how I added it, not sure about the label 999

I got an error where highlighted below. I still cant understand where the table of results will go? or should.

Code:
Sub Macro1()Dim a(10000), b(10000)
For j = 2 To 10000
[B][COLOR=#ff0000]If Cells(j, k) = "" Then[/COLOR][/B] GoTo 999
For k = 65 To 83 Step 2
If Cells(j, k) <> "" Then GoTo 20 Else GoTo 100
20 Sum = Sum + 1
a(Sum) = Cells(j, k)
b(Sum) = Cells(j, k + 1)
100 Next k
Next j
For Z = 2 To 2 + Sum
tot = tot + 1
Cells(Z, 1) = a(tot)
Cells(Z, 2) = b(tot)
Next Z
999: End Sub
 
Upvote 0
delete the : after 999

the error is my fault - the red line should come immediately after for k =65 to 83 step 2

SORRY!!!!
 
Upvote 0
No problem, appreciate the help.

Ok so I used the following. I run it and get no apparent errors. However, I dont see any results or understand where the new table should show?

Thanks.

Code:
Sub Macro1()Dim a(10000), b(10000)
For j = 2 To 10000
For k = 65 To 83 Step 2
If Cells(j, k) = "" Then GoTo 999
If Cells(j, k) <> "" Then GoTo 20 Else GoTo 100
20 Sum = Sum + 1
a(Sum) = Cells(j, k)
b(Sum) = Cells(j, k + 1)
100 Next k
Next j
For Z = 2 To 2 + Sum
tot = tot + 1
Cells(Z, 1) = a(tot)
Cells(Z, 2) = b(tot)
Next Z
999 End Sub
 
Upvote 0
Sub Macro1()Dim a(10000), b(10000)
For j = 2 To 10000
For k = 65 To 83 Step 2
If Cells(j, k) = "" Then GoTo 999
If Cells(j, k) <> "" Then GoTo 20 Else GoTo 100
20 Sum = Sum + 1
a(Sum) = Cells(j, k)
b(Sum) = Cells(j, k + 1)
100 Next k
Next j
For Z = 2 To 2 + Sum
tot = tot + 1
Cells(tot, 105) = a(tot) ################
Cells(tot, 106) = b(tot) ##############
Next Z
999 End Sub

my error again
results should appear starting in AD1
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,819
Members
449,469
Latest member
Kingwi11y

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