Hi,
I'm trying to get my vba code to select a variable length of rows. However, I think I formatted it wrong, because it returns nothings. I am still researching the issue. Below is my code and attached to this thread is my workbook.
The macro is title Pivot_Relative
Thanks for your help.
Sub Pivot_relative()
On Error Resume Next
ThisWorkbook.Worksheets("Output").Delete
Sheets.Add.Name = "Output"
Dim wk1 As Worksheet
Set wk1 = ThisWorkbook.Worksheets("Source")
Set FinalRow = ThisWorkbook.Worksheets("Source").Cells(Rows.Count, 1).End(xlUp).Row
Dim wk2 As Worksheet
Set wk2 = ThisWorkbook.Worksheets("Output")
ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
wk1 & "R4C2:R" & FinalRow & "C4", Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="Output!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion15
Sheets(wk2).Select
Cells(3, 1).Select
With wk2.PivotTables("PivotTable1").PivotFields("Name")
.Orientation = xlRowField
.Position = 1
End With
End Sub
Bookmarks