+ Reply to Thread
Results 1 to 11 of 11

Using variable for Autofilter Criteria1

  1. #1
    Registered User
    Join Date
    08-13-2017
    Location
    India
    MS-Off Ver
    2010
    Posts
    46

    Using variable for Autofilter Criteria1

    I have the following snippet from my VBA

    Please Login or Register  to view this content.
    I know there is something wrong here

    1) If I record a macro, I get Criteria1:="1" if 1 is not filtered out, Criteria2:="2" if 2 is not filtered out and so on...

    How can I get 1 through 52 in a loop so that I can have 1,2,...52 not filtered out sequentially and do tasks I subsequently want to carry out?

    Is the above approach correct. I think its wrong because I set Criteria1:=i and i is an integer above

    Whereas, in the recorded macro, 1 or 2 or...appear in double quotes "1", or "2",....

    Can anyone help to Set Criteria1 as a variable because I want to filter out 52 times (1 first time, 2 second time, 3 third time,.....52 52nd time)

    Thanks a lot in advance
    Last edited by ateestructural; 09-17-2017 at 07:57 AM.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: VBA urgent help

    Please read and adhere to these simple rules!

    1. Use concise, accurate thread titles. Your post title should describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change the title of the thread, click EDIT on the original post, then click the Go Advanced button, then change the title. If two or more days have passed, the EDIT button will not appear, and you need to ask a moderator to change the title.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    08-13-2017
    Location
    India
    MS-Off Ver
    2010
    Posts
    46

    Re: Using variable for Autofilter Criteria1

    Sorry. Corrected

  4. #4
    Registered User
    Join Date
    08-13-2017
    Location
    India
    MS-Off Ver
    2010
    Posts
    46
    Will be extremely grateful if helped

  5. #5
    Registered User
    Join Date
    06-16-2016
    Location
    Greece
    MS-Off Ver
    2013
    Posts
    69

    Re: Using variable for Autofilter Criteria1

    You should include your worksheet with actual data if you wanna get help...

  6. #6
    Registered User
    Join Date
    08-13-2017
    Location
    India
    MS-Off Ver
    2010
    Posts
    46

    Re: Using variable for Autofilter Criteria1

    The file is too large to attach unfortunately. The file is 21 MB but the allowed is 10MB

    Here is the code that is not working(the bold line is not working).

    I shall be extremely grateful if helped

    Please Login or Register  to view this content.
    Last edited by ateestructural; 09-18-2017 at 01:47 AM.

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Using variable for Autofilter Criteria1

    Then reduce the file to e.g. 1 MB.

    Don't forget to remove confidential information.

    We are not interested in the whole file, just a small part of it, thats shows the problem and so we could test the offered solution.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Using variable for Autofilter Criteria1

    Do you mean?
    Please Login or Register  to view this content.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Using variable for Autofilter Criteria1

    Quote Originally Posted by ateestructural View Post
    I think its wrong because I set Criteria1:=i and i is an integer above
    Hi,

    Did you actually test it? That code should work as you have posted it.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  10. #10
    Registered User
    Join Date
    08-13-2017
    Location
    India
    MS-Off Ver
    2010
    Posts
    46

    Re: Using variable for Autofilter Criteria1

    Yes, I tested it. IT doesn't work

    I have attached my bile: Book_example.xlsm

    There is no confidential information. It is a concise form of my actual workbook

    You have to hit the button "GetDetails" which will call the VBA code
    Attached Files Attached Files

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Using variable for Autofilter Criteria1

    I was referring to the original code. The code in post 6 merely needs to read
    Please Login or Register  to view this content.
    since Subtotal is not a VBA function.

+ 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. [URGENT][Help with a VBA Macro - Maximum with criterias][URGENT]
    By mahmoudmerhi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2013, 03:39 PM
  2. Need urgent help with error! Urgent!
    By heidenman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-03-2009, 04:31 AM
  3. please help! really urgent! thanks
    By starlover123 in forum Excel General
    Replies: 1
    Last Post: 07-03-2009, 07:19 PM
  4. urgent help
    By b166er in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-22-2006, 08:45 PM
  5. urgent, help!
    By eeehwc in forum Excel General
    Replies: 5
    Last Post: 11-26-2005, 01:30 PM
  6. Urgent-Urgent VBA LOOP
    By Jeff in forum Excel General
    Replies: 0
    Last Post: 10-06-2005, 01:05 PM
  7. [SOLVED] Hi All, need urgent help please.
    By FrigidDigit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2005, 12:05 PM
  8. Please Help (Urgent)
    By jyang in forum Excel General
    Replies: 0
    Last Post: 08-07-2005, 08:23 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