Advanced filter from another workbook

HughT

Board Regular
Joined
Jan 6, 2012
Messages
113
Office Version
  1. 365
Platform
  1. Windows
Fluff very kindly posted the following code to enable the automation of advanced filtering from one worksheet to another in the same workbook for variable criteria without having to reinput the criteria each time. But how would this be done from another workbook? The data is in a workbook called Project Log which has many worksheets containing sensitive information. I want to create a separate workbook for general users (called Project Lookup) which would enable them to run the advanced filter from that location without any risk of accessing the sensitive data. The worksheet for this would be called Project Data.

Is this possible?

Many thanks

HT


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address(0, 0) = "C4" Then
With Sheets("Pcode").Range("A4:D200")
.AdvancedFilter xlFilterCopy, Me.Range("C3:C4"), Me.Range("A6:D6"), False
.AutoFilter
End With
End If
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
The simplest solution is to open the Project Log workbook momentarily and do the advanced filter on the required sheet (here named "Data Sheet") in that workbook:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim DataWorkbook As Workbook
    
    If Target.CountLarge > 1 Then Exit Sub
    
    If Target.Address(0, 0) = "C4" Then
        Application.ScreenUpdating = False
        Set DataWorkbook = Workbooks.Open("C:\folder\path\to\Project Log.xlsx") 'CHANGE PATH
        With DataWorkbook.Worksheets("Data Sheet").Range("A4:D200") 'CHANGE SHEET NAME
            .AdvancedFilter xlFilterCopy, Me.Range("C3:C4"), Me.Range("A6:D6"), False
            .AutoFilter
        End With
        DataWorkbook.Close False
        Application.ScreenUpdating = True
    End If
    
End Sub
If you don't want to open the Project Log workbook - and I suppose there is a risk that it might remain open, for whatever reason - then a better solution would be an SQL query of the Project Log workbook using ADODB.
 
Upvote 0
Very many thanks for this. Apologies, I should have mentioned that both workbooks will be held in Sharepoint. Will this make a difference, or do I just copy the Sharepoint path into where you have the reference to C drive?

Thank you

HT
 
Upvote 0
Yes, try using the Sharepoint path, although I've never used Sharepoint so don't know if it will work.

As a test, have both files on your local drive and see if the time taken to open the Project Log workbook is acceptable - it might not be if it's a large file with many worksheets. In that case we could try the ADODB approach.
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,088
Members
453,021
Latest member
Justyna P

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