I have a pivot table that I create weekly to include the new week's data, as well as the rest of the weeks in the year. I'd like for the macro to pull all of the columns like "WE" into the pivot table so that it includes the current week. Below is what the code looks like now. Is there a way to tell the macro to pull columns based on "field name like" language? Thanks in advance for any help you can give me! I've been able to get this far, but it doesn't loop the headers to find all of the columns that have WE headers.
Sub AddPTFields()
Dim PT As PivotTable
Dim PF As PivotField
Dim FldName As String
Dim LastCol As Integer
Dim TxtStr As String
Dim wsName As String
'The sheet the Pivot Table is on is on Sheet1
wsName = "Total Daily Volume Data"
FldName = Sheets(wsName).Cells(1, x + 1).Value '''Not cycling through FldNames....Stays on 1st Field???
Set PT = ActiveSheet.PivotTables("PivotTable2")
Set PF = PT.PivotFields(FldName)
LastCol = Sheets(wsName).Range("A1").SpecialCells(xlCellTypeLastCell).Column
TxtStr = LCase(CStr(Cells(1, x + 1)))
For x = 7 To LastCol 'Date fields that could contain *we begin at this column(7)
If PF Like "we*" Then
PT.AddDataField PF, "Sum of " & TxtStr, xlSum
End If
Next x
End Sub
Bookmarks