extract from pivot vba

Sayf1

New Member
Joined
Jul 17, 2018
Messages
8
Hey all,

so let’s say I have a pivot table that has many categories. I want to
tell the vba to onlygrab the categories in colomn A and not the blank cells and paste them in tab “sheets” in colomn s.

How would i do that?

Thank you in advance !
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hey Sayf1,

Try the below code which copies the data from 1 sheet to another without the blanks regardless whether the original data is a pivot table or not. Make sure you have a sheet called "sheets" in your file :)

Rich (BB code):
Sub CopyFromPivot()
Dim Ws1 As Worksheet, Ws2 As Worksheet, Ar1() As Variant, Ar2() As Variant, Cnt As Long
Set Ws1 = Sheets("Sheet1") 'change the sheet name where you have your pivot table
Set Ws2 = Sheets("sheets")
Ar1 = Ws1.Range("A1", Ws1.Range("A" & Rows.Count).End(xlUp)).Value 'change the column to take data from
ReDim Ar2(1 To UBound(Ar1))
For i = LBound(Ar1) To UBound(Ar1)
    If Ar1(i, 1) <> "" Then
        Cnt = Cnt + 1
        Ar2(Cnt) = Ar1(i, 1)
    End If
Next
Ws2.Range("S1").Resize(UBound(Ar2)).Value = Application.Transpose(Ar2)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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