Results 1 to 1 of 1

vba autofilter not working for numbers

Threaded View

  1. #1
    Registered User
    Join Date
    01-01-2013
    Location
    melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    55

    vba autofilter not working for numbers

    this code works when I look up a text field but I need it to look up from a field of numbers


    so if I have 2 columns 1 is a 4 digit product number the second is the product name, if range A1:A3 looks up product names it works but if I try to do the same for the product code it doesn't (yes I changed the auto filter columns to the relevant field)


    Dim vCrit As Variant
    Dim wsO As Worksheet
    Dim wsL As Worksheet
    Dim rngCrit As Range
    Dim rngOrders As Range
    Set wsO = Worksheets("rom")
    Set wsL = Worksheets("data")
    Set rngOrders = wsO.Range("$A$1").CurrentRegion
    Set rngCrit = wsL.Range("A1:A3")
    
    
    vCrit = rngCrit.Value
    
    rngOrders.AutoFilter Field:=2, Criteria1:=Application.Transpose(vCrit), Operator:=xlFilterValues
    **EDIT**
    managed to find solution that works, code for anyone interested, added in split & join. seems to make VBA recognise the numbers as text or something...


    Dim vCrit As Variant
    Dim wsO As Worksheet
    Dim wsL As Worksheet
    Dim rngCrit As Range
    Dim rngOrders As Range
    Set wsO = Worksheets("rom")
    Set wsL = Worksheets("data")
    Set rngOrders = wsO.Range("$A$1").CurrentRegion
    Set rngCrit = wsL.Range("A1:A3")
    
    
    vCrit = rngCrit.Value
    
    rngOrders.AutoFilter Field:=15, Criteria1:=Split(Join(Application.Transpose(vCrit))), Operator:=xlFilterValues
    Last edited by rossg; 01-15-2015 at 11:02 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Autofilter criteria not working
    By Zeos6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-06-2013, 05:49 PM
  2. Autofilter not working
    By Zeos6 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-04-2013, 03:43 PM
  3. Autofilter not working
    By psbailey42 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-26-2013, 07:15 AM
  4. [SOLVED] autofilter not working
    By ACTBOB in forum Excel General
    Replies: 2
    Last Post: 07-21-2006, 05:20 PM
  5. Autofilter Not working
    By cyndi in forum Excel General
    Replies: 3
    Last Post: 02-14-2005, 07:06 PM

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