Open another Workbook and apply filter

Martin_H

Board Regular
Joined
Aug 26, 2020
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Hi all,

whit this code I would like to open another Excel Worbook (which is locked and shared) if not already opened and apply the filter on Worksheet named "1" to the cell A1 (cell A1 is a header, but it is not a table just a range). So basically after filter is done I want to see only numbers 2, if there are any, under the cell A1.

Excel Formula:
Sub ApplyFilter()

    On Error Resume Next: Err.Clear: Dim wb As Workbook
    Set wb = Workbooks("New Microsoft Excel Worksheet.xlsm"): wb.Activate
    If Err.Number > 0 Then Set wb = Workbooks.Open(Filename:="C:\Users\DLBV9NJ\Desktop\New Microsoft Excel Worksheet.xlsm", ReadOnly:=False)
    If Not wb Is Nothing Then wb.Worksheets("1").Activate
Sheets("1").Visible = True

    With Worksheets("1")
.Activate
.Range("A1").AutoFilter field:=1, Criteria1:="2"
    End With

End Sub

Code works ok, it opens the Workbook I want but will not filter anything meanwhile filtering on that Shared/Locked Workbook is allowed. I have locked it before with the code below (manual filtering on that Shared/Locked Workbook is working).

Excel Formula:
Sub Protect1()

    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowSorting:=True, AllowFiltering:=True, UserInterfaceOnly:=True

End Sub

Please help me with this one.


Thank you!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
After removing error traps I am getting Run-time error 1004. Application-defined or object-defined error.
 
Upvote 0
Does a line in the code get highlited?

I assume you are trying to set the workbook, before it is opened.
 
Upvote 0
Nothing got highlighted at all.

The code works perfectly until I set the Workbook to "Shared" state.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,189
Members
452,616
Latest member
intern444

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