Select case and a loop

rdw72777

Well-known Member
Joined
Apr 5, 2005
Messages
723
So I have pulled two bits of code that worked well separately, but don't go well together. One is for a select case within some pivot table code to pass through values in the case as pivottable filters. Another is trying to loop through a number of values to get them passed through to the case statement.

What I'm hoping for is that I will have a number of values in some rows in column A, and I'd like to pass all fo those values through as filters in a pivot table, but anything no in this list of values should not be filtered. However, the way the code works is that it goes through each value in my list and if its not that value, it doesn't get filtered. I knwo this is a coding mistake but I'm not sure how to fix it. My loop using the variable j could have anywhere from 1 value to 180, but the select case will only pick the very last one, exactly as the code says. how can i pass all of these values through the case statement all at once and eliminate the loop around the Select-Case?

Code:
With PivotTbl.PivotFields("Product")
        For i = 1 To .PivotItems.Count
            With .PivotItems(i)
            
                FormShtLastRow = FormSheet.Cells(Rows.Count, 1).End(xlUp).Row
                If FormShtLastRow > FormShtBlackRow + 1 Then
                
                    For j = FormShtBlackRow + 2 To FormShtLastRow
                
                    Select Case .Name
                        Case FormSheet.Cells(j, 1).Value
                            .Visible = True
                        Case Else
                            .Visible = False
                    End Select
                    
                    Next j
                
                End If
            End With
        Next i
    End With
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top