I have a pivot table which uses calculated items . My Input for the calculated item changes dynamically. I have been asking the User to Input the formula using InputBox Method. But now, I want to set it to dynamic but I couldn't make them work. Here goes my data,

```
   Category Checks
    18-20   Yes
    18-20   Yes
    16-18   Yes
    16-18   Yes
    20-24   Yes
    24-30   Yes
    30-35   Yes
    35-40   Yes
    14-16   Yes

```

And this is the Pivot table output that I am looking for ,

```
    Column Labels       
                Less than 20    More than 20    Grand Total
Count of Checks 5              4                9

```

Less than 20 and More than 20 are calculated items. Initially I was hardcoding the formula like this - 

```
ActiveSheet.PivotTables("PivotTable5").PivotFields("Category").CalculatedItems. _
        Add "Less than 20", "='16-18' +'18-20'", True
ActiveSheet.PivotTables("PivotTable5").PivotFields("Category").CalculatedItems. _
        Add "More than 20", "='20-24' +'24-30' +'30-35' +'35-40'", True

```

There were no problems when all these categories ( '16-18', '18-20' etc.,) are present. But it is not present in some of the sheets.

Then I asked the User to Input the Formula by setting a String Variable. But now, I want it to be more dynamic and the formula to happen automatically. Kindly help me with this. I tried a lot FOR 2 days, but I couldn't get the logic going.

I am able to get the Unique values inside the column category at the moment. Now, How do I set it inside the formula

```
colmz = WorksheetFunction.Match("Category", Sheets(Ssheet1").Rows(1), 0)
Nrowz = ActiveSheet.Cells(Rows.Count, colmz).End(xlUp).Row
B = GetColumnName(colmz)

    For i = 2 To Nrowz
        CellVal = Sheets("Sheet1").Range(B & i).Value
        On Error Resume Next
        Col.Add CellVal, Chr(34) & CellVal & Chr(34)
        On Error GoTo 0
    Next i

    For Each itm In Col
        Debug.Print itm
    Next

```