For Next loop on Pivot Table field

Hermac

New Member
Joined
Sep 5, 2016
Messages
21
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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
My problem is solved. I had just been stupid. Please disregard my post of yesterday
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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