VenkateshRajaganesan
New Member
- Joined
- May 27, 2022
- Messages
- 7
- Office Version
- 365
- 2011
"i want to filter varray varilable items only but this code brings blanks"
Sub DuplicateValuesFromSelection()
Dim myRange As Range
Dim myCell As Range
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set GL = wb.Sheets("GL Paste")
Set PT = wb.Sheets("Sheet1 PT")
Set RGL = wb.Sheets("RawGL PT")
Dim vArray As Variant
Dim i As Integer, j As Integer
Dim pvFld As PivotField
Set pvFld = ActiveSheet.PivotTables("PivotTable1").PivotFields("CTRL")
Yrow = PT.Range("y1")(Rows.Count, 1).End(xlUp).Row
vArray = PT.Range("Y1:Y" & Yrow)
pvFld.ClearAllFilters
With pvFld
For i = 1 To pvFld.PivotItems.Count
j = 1
Debug.Print pvFld.PivotItems.Count
Do While j <= UBound(vArray, 1) - LBound(vArray, 1) + 1
If pvFld.PivotItems(i).Name = vArray(j, 1) Then
pvFld.PivotItems(pvFld.PivotItems(i).Name).Visible = True
Exit Do
Else
On Error Resume Next
pvFld.PivotItems(pvFld.PivotItems(i).Name).Visible = False
End If
j = j + 1
Loop
Next i
End With
End Sub
Sub DuplicateValuesFromSelection()
Dim myRange As Range
Dim myCell As Range
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set GL = wb.Sheets("GL Paste")
Set PT = wb.Sheets("Sheet1 PT")
Set RGL = wb.Sheets("RawGL PT")
Dim vArray As Variant
Dim i As Integer, j As Integer
Dim pvFld As PivotField
Set pvFld = ActiveSheet.PivotTables("PivotTable1").PivotFields("CTRL")
Yrow = PT.Range("y1")(Rows.Count, 1).End(xlUp).Row
vArray = PT.Range("Y1:Y" & Yrow)
pvFld.ClearAllFilters
With pvFld
For i = 1 To pvFld.PivotItems.Count
j = 1
Debug.Print pvFld.PivotItems.Count
Do While j <= UBound(vArray, 1) - LBound(vArray, 1) + 1
If pvFld.PivotItems(i).Name = vArray(j, 1) Then
pvFld.PivotItems(pvFld.PivotItems(i).Name).Visible = True
Exit Do
Else
On Error Resume Next
pvFld.PivotItems(pvFld.PivotItems(i).Name).Visible = False
End If
j = j + 1
Loop
Next i
End With
End Sub