+ Reply to Thread
Results 1 to 3 of 3

Filtering in another workbook, copying filtered data and pasting in source workbook

  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Filtering in another workbook, copying filtered data and pasting in source workbook

    Hi Everyone...

    I signed up on the forum because I saw some really beneficial threads on here. I am having an issue filtering a sheet in workbook2 based on criteria in a sheet in workbook 1. I am using the following code. The error I get is 'subscript out of range.'

    What I am trying to do:
    1. Filter in workbook 2 sheet 3 based on a criteria named as a range in workbook 1 sheet 1 (criteria range name = CritList)
    2. Once this is done, copy the filtered data (all of it..about 8 columns and multiple rows)
    3. Paste it in workbook 1 sheet 4
    4. Message box on sheet3 in workbook 1 showing data has imported


    Code:

    Sub ImportSpend2()

    Dim vCrit As Variant
    Dim wsO As Worksheet
    Dim wsL As Worksheet
    Dim rngCrit As Range
    Dim rngOrders As Range
    Set wsO = Workbooks("workbook2.xlsx").Sheets("sheet3")
    Set wsL = Workbooks("workbook1.xlsm").Sheets("sheet1")
    Set rngOrders = wsO.Range("$A$1").CurrentRegion
    Set rngCrit = wsL.Range("CritList")


    vCrit = rngCrit.Value

    Workbooks.Open Filename:="D:\Documents and Settings\adasdas\Desktop\dasdasdasda\workbook2.xlsx"
    Sheets("sheet3").Select

    rngOrders.AutoFilter _
    Field:=1, _
    Criteria1:=Application.Transpose(vCrit), _
    Operator:=xlFilterValues
    Cells.Select
    Selection.Copy

    Windows("workbook1.xlsm").Activate
    Sheets("sheet4").Select
    Cells.Select

    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False

    Windows("workbook2.xlsx").Activate
    ActiveWorkbook.Close
    Windows("workbook1.xlsm").Activate


    Sheets("Sheet3").Select
    MsgBox "Spend data imported."

    End Sub

  2. #2
    Registered User
    Join Date
    11-05-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Filtering in another workbook, copying filtered data and pasting in source workbook

    Anyone willing to help???

  3. #3
    Registered User
    Join Date
    11-05-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Filtering in another workbook, copying filtered data and pasting in source workbook

    Come on..anyone?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1