VBA to filter a worksheet in a different workbook

CTRDevelopments

New Member
Joined
Nov 16, 2020
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a master excel document which holds all of the VBA code. I need this to open up a different excel BOM and remove some lines from it. I have the code open up the second excel file but the filering and row deletion code (looking in this case for a row in column c containing "Roof Plan", seem to try to filter the master excel which clearly goes badly wrong. I am not quite sure what I have done wrong here as I have tried to set the BOM file as the active worksheet etc.

If I copy the code into the BOM file it works as intended so I can only assume it is something to do with the vba residing on the master file not the BOM file.

Any help is much appreciated

cheers

VBA Code:
Dim MyFilePath As String
Dim FileName As String
Dim FullFileName As String

MyFilePath = ThisWorkbook.Path
FileName = "\Drawings\Complete_BOM.xlsm"
FullFileName = MyFilePath & FileName

Set WkB = Workbooks.Open(FullFileName)
Workbooks("Complete_BOM.xlsm").Activate
Worksheets("Sheet1").Activate

    With ActiveSheet
        .AutoFilterMode = False
        With Range("c1", Range("c" & Rows.Count).End(xlUp))
            .AutoFilter 1, "Roof Plan"
            On Error Resume Next
            .Offset(1).SpecialCells(12).EntireRow.Delete
        End With
        .AutoFilterMode = False
    End With
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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