Hi
I pretty new to VBA and have a problem I need some help solving. I have one sheet with a range (MyRange) containing the sheet names I would like to loop through. If the sheet name matches the name in MyRange I would like the macro to create a pivottable on a sheet that already is created and named name in MyRange & Report. The code I’ve come up with and that have gotten me nowhere is as follows:
Option Explicit
Sub RawData9_CreatePivots()
Dim MyCell As Range, MyRange As Range, ws As Worksheet, Arr() As Variant, wsName As Variant
Application.ScreenUpdating = False
Set MyRange = Sheets("data").Range("k1")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
Set wsName = MyRange
Arr = Array(wsName)
For Each ws In ThisWorkbook.Worksheets
End Sub
‘Any help or clue is welcome.
‘Much appreaciated
I pretty new to VBA and have a problem I need some help solving. I have one sheet with a range (MyRange) containing the sheet names I would like to loop through. If the sheet name matches the name in MyRange I would like the macro to create a pivottable on a sheet that already is created and named name in MyRange & Report. The code I’ve come up with and that have gotten me nowhere is as follows:
Option Explicit
Sub RawData9_CreatePivots()
Dim MyCell As Range, MyRange As Range, ws As Worksheet, Arr() As Variant, wsName As Variant
Application.ScreenUpdating = False
Set MyRange = Sheets("data").Range("k1")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
Set wsName = MyRange
Arr = Array(wsName)
For Each ws In ThisWorkbook.Worksheets
For Each wsName In Arr
If wsName = ws.name Then
ActiveSheet.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:=Range("A1").CurrentRegion).CreatePivotTable _
TableDestination:=Worksheets(wsName & " report")
SourceData:=Range("A1").CurrentRegion).CreatePivotTable _
TableDestination:=Worksheets(wsName & " report")
End If
Next wsName
Next wsEnd Sub
‘Any help or clue is welcome.
‘Much appreaciated