+ Reply to Thread
Results 1 to 2 of 2

VBA macro with advanced filtering

  1. #1
    Registered User
    Join Date
    06-27-2016
    Location
    -
    MS-Off Ver
    -
    Posts
    3

    VBA macro with advanced filtering

    Hi all,

    I am using the below code to try to perform the following actions
    1. From the bidding workbook execute the macro
    2. Macro opens a database file (AllData)
    3. Macro is supposed to filter this database file by using a criteria defined in the bidding workbook (cell C3, sheet Summary)
    4. Macro pastes filtered output in workbook Vendor_Code_Data

    The issue I am facing is that the filtering is not executing for some reason, it copies and pastes the entire file.

    I tried to look into the value that the variable takes but could not find it. Would someone have an idea?

    Thanks a lot for your help

    _______________________



    Sub data_manipulation()

    Application.ScreenUpdating = False

    Dim AllData As String
    Dim VendorFile As String
    Dim Bidding As String
    Dim FilterRange As Range, Criteria As Range, TargetRange As Range
    Dim WB_Data As Workbook, WB_Vendor As Workbook, WB_Bidding As Workbook
    Dim WS1 As Worksheet, WS2 As Worksheet, WS3 As Worksheet


    AllData = "results.xls"
    VendorFile = "Vendor_Code_Data.xlsx" '->>>>> name to adapt'
    Bidding = "201804_Bidding.xlsm"

    Set WB_Bidding = ThisWorkbook
    Set WB_Vendor = Workbooks.Open(ActiveWorkbook.Path & "\" & VendorFile)
    Set WB_Data = Workbooks.Open(ActiveWorkbook.Path & "\" & AllData)


    If WB_Vendor Is Nothing Then
    MsgBox "You must have your Target WorkBook Open."
    Exit Sub
    End If

    ' ---- Assign WorkSheet Variables
    Set WS1 = WB_Data.Worksheets("results")
    Set WS2 = WB_Vendor.Worksheets("Vendor_Code_Data")
    Set WS3 = WB_Bidding.Worksheets("Summary")

    ' ---- Clear Target range of old Data
    WS2.UsedRange.ClearContents

    ' ---- Set variables to specific Ranges

    Set FilterRange = WS1.Range("A1").CurrentRegion
    Set Criteria = WS3.Range("C3").CurrentRegion
    Set TargetRange = WS2.Range("A1")


    ' ---- Do Advanced Filter using variables

    FilterRange.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=TargetRange, CriteriaRange:=Criteria

    Application.ScreenUpdating = False

    End Sub

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA macro with advanced filtering

    Can you attach your worksheets? Use the facility provided by clicking the 'Go Advanced' button. The toolbar paper clip does not work.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro code for advanced filtering
    By kasun in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2015, 11:04 PM
  2. Recording advanced filtering macro
    By niukvba in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-02-2014, 03:48 AM
  3. [SOLVED] Advanced Filtering Macro takes out the existing filter
    By sachins19 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-21-2014, 09:25 AM
  4. [SOLVED] Easy filtering method via vba/formula/advanced filtering?
    By jedemeyer1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-10-2014, 12:35 AM
  5. More advanced advanced filtering
    By Acceleracer in forum Excel General
    Replies: 2
    Last Post: 02-06-2014, 09:02 PM
  6. Advanced Filtering by Date (or Macro) Help
    By Alexis in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-08-2006, 01:15 PM
  7. [SOLVED] Macro to perform Advanced Filtering
    By Spencer Hutton in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-23-2005, 09:07 AM

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