For Next loop on Pivot Table field

Hermac

New Member
Joined
Sep 5, 2016
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hello,

I wrote this code to repeatedly copy part of a pivot table in a workbook (source) end valuepaste it in another workbook .(target).
Then go back to the pivot table where a field called "Groupe" should itterate from A to S. For those letters I use the string variable "Groep"
I get stuck all the time on the 23rd line (blue line) of my code. Can someone help me out here?
Thank you very very much
Herman


Dim i As Integer, j As Integer, k As Integer, c As Range, R As Range

Dim Mes As String, Regio As String, Groep As String

Dim PerNr As Range





Sub CopyToCollector()

Dim WbBron As Workbook, WbDoel As Workbook

Dim WsBron As Worksheet, WsDoel As Worksheet, Bronvlak As Range

Set WbBron = ActiveWorkbook: Set WsBron = ActiveSheet

If MsgBox("Staat er een DOELBOEK open ?", vbYesNo) = vbNo Then

Mes = Application.InputBox("Hoe moet het Doelboek heten?", Type:=2)

Workbooks.Add.SaveAs Filename:=Mes

Set WbDoel = ActiveWorkbook: Set WsDoel = ActiveSheet: Set R = [C2]

Else

Set R = Application.InputBox(prompt:="KLIK ERGENS op de EERSTVOLGENDE DOELCEL op het DOELBLAD in het DOELBOEK", Type:=8)

Set WsDoel = R.Parent: Set WbDoel = R.Parent.Parent

End If

WbBron.Activate: WsBron.Activate

Regio = Application.InputBox("Welke Regio heb je geselecteerd?", Type:=2)

ActiveSheet.PivotTables("Draaitabel1").PivotFields("Groep/groupe").CurrentPage = "(All)"

ActiveSheet.[C1:C300].Find("Totaal Werknemers").Resize(3, 20).Copy

WbDoel.Activate: WsDoel.Activate: R.PasteSpecial xlPasteValues

R.Offset(0, -2).Resize(3, 1) = Regio

R.Offset(0, -1).Resize(3, 1) = "Alle"

Set R = R.Offset(3, 0)

WbBron.Activate: WsBron.Activate

For i = 65 To 83

Groep = Chr(i)

ActiveSheet.PivotTables("Draaitabel1").PivotFields("Groep/groupe").CurrentPage = Groep

ActiveSheet.[C1:C300].Find("Totaal Werknemers").Resize(3, 20).Copy

WbDoel.Activate: WsDoel.Activate: R.PasteSpecial xlPasteValues

R.Offset(0, -2).Resize(3, 1) = Regio

R.Offset(0, -1).Resize(3, 1) = Groep

Set R = R.Offset(3, 0)

Next i

End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
My problem is solved. I had just been stupid. Please disregard my post of yesterday
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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