VBA Filter PowerPivot Field, based on range cell values but skipping Errors.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
719
Hello Friends, Hope all is safe & Well!

The following code, filters the PowerPivot's field PatientID, based on the Range B2:B1000 of sheet DBs.

The code works provided that whatever is in B exists in the PowerPivot field, If it doesn't I get an error.
How can I have the code run anyway & skip the cells in B that don’t exist in the field.

End result, filter only whatever is in B and matches what is in the field.

Your kind support is and always appreciated please.

Code:
Option Explicit

Sub Test1()

Dim MyString As String
Dim ArrVisiblelist()
Dim fldName As String
fldName = "[Proc XLSM].[PatientID].[PatientID]"
Dim lr As Long, i As Long
lr = Sheets("DBs").Range("B" & Rows.Count).End(xlUp).Row

ReDim ArrVisiblelist(1 To lr - 1)

For i = 2 To lr

ArrVisiblelist(i - 1) = "[Proc XLSM].[PatientID].&[" & Sheets("DBs").Cells(i, 2).Value & "]"

Next I

ActiveSheet.PivotTables("PT").PivotFields(fldName).VisibleItemsList = ArrVisiblelist

End Sub
 

Attachments

  • 1.png
    1.png
    30.4 KB · Views: 6
  • 2.png
    2.png
    6.1 KB · Views: 6

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Watch MrExcel Video

Forum statistics

Threads
1,132,872
Messages
5,655,725
Members
418,234
Latest member
jdorfma

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
Top