I have an excel sheet named InputData. I have 9 different columns present at the moment. I want to have a loop which counts the number of columns in the excel sheet. Also, for each value of the counter, I want to select that individual column and the last column (to be selected default for each iteration). Once I have selected the necessary columns, the idea is to do a pivot table and draw a bar chart. Then again dynamically goto the next column via the counter value and the last column(to be selected default for each iteration) and so on. I am not able to figure out how to go about it. Any help in this matter is highly appreciated. Thanks in advance!!
For i = 1 To lastColno
' Pivot Table Code
Range("B1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Paste
Sheets("BuildData").Select
Range("J1").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("B1").Select
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C1:R2641C2", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet2!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14
Sheets("Sheet2").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("_KOLA_5SX")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Claim?")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Claim?"), "Count of Claim?", xlCount
Next i