VBA: Filter then Paste into Different Workbook

nickshep85

New Member
Joined
Mar 21, 2012
Messages
37
I am very new to VBA and am trying to find a way to apply an autofilter and then paste the results onto a specific sheet in a different workbook. Sadly, my small grasp of VBA has stopped when it comes to this :confused:. Can anyone help me please? Details are as below:


  • The Workbook that I need filtered is called PriceFile and could have anywhere between 1 & 3 sheets;
  • The data that needs to be filtered will always be Column I, and will be either TRUE or FALSE;
  • My destination Workbook is called ImportFile, and has two Sheets: "Tyres" and "Mechanical"
  • The Sheets in the destination Workbook have two rows at the top which I use for headers
  • All TRUE values from PriceFile need to be copied into the next available Row in "Mechanical" tab
  • All FALSE values from PriceFile need to be copied into the next available Row in "Tyres"

I'm sure that there would be a way of looping through Sheets to filter, then copy and paste into the next Row in the required Sheet, but I am getting very, VERY, lost.

Please can someone help me with this problem, as I don't know where to begin with this.

Many thanks in advance.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Following on from this, I have tried to use a code from someone else which works partly.

The code below copies all TRUE value Rows and pastes them into the Mechanical tab on my ImportFile Workbook, but then does not move onto the next sheet to do the same. Can anyone suggest how I would get this to loop onto the next sheet?

Code:
Workbooks("PriceFile.xls").Activate
    m = 3
    t = 3
    For i = 1 To Workbooks("PriceFile.xls").Sheets.Count
        Worksheets(i).Select
        For l = 1 To Cells(Rows.Count, "I").End(xlUp).Row
            If Cells(l, 9).Value = "True" Then
                Rows(l).Copy
                Workbooks("ImportFile.xls").Activate
                Worksheets("Mechanical").Select
                Cells(m, 1).Select
                ActiveSheet.Paste
                m = m + 1
            End If
            If Cells(l, 9).Value = "False" Then
                Rows(l).Copy
                Workbooks("ImportFile.xls").Activate
                Worksheets("Tyres").Select
                Cells(t, 1).Select
                ActiveSheet.Paste
                t = t + 1
            End If
            Workbooks("PriceFile.xls").Activate
            Worksheets(i).Select
        Next l
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,487
Members
452,917
Latest member
MrsMSalt

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