+ Reply to Thread
Results 1 to 9 of 9

autofilter macro using variable

  1. #1
    Registered User
    Join Date
    07-25-2012
    Location
    aus
    MS-Off Ver
    Excel 2003
    Posts
    15

    autofilter macro using variable

    Good day everyone, im trying to get a autofilter code to work using a macro. the issue im facing is that the code is split up into different subroutines, so 1 for each sheet and the variable being used is called on a seperate subroutine, how do you place the variable in a cell on each sheet if its been called in a priior sub routine? thanks

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,440

    Re: autofilter macro using variable

    No workbook, no data, no code ... you're not giving much away.

    Couldn't even hazard a guess based on this description.

    Sorry, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-25-2012
    Location
    aus
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: autofilter macro using variable

    okay well this code is what gets the filename:
    Please Login or Register  to view this content.
    now i need to assign that to some sort of global variable so in a seperate sub routine i can place it on each individual sheet in a cell, then call from that cell using this routine for the autofilter:

    Please Login or Register  to view this content.


    ---------- Post added at 08:30 AM ---------- Previous post was at 08:27 AM ----------

    alternatively is their a way to make:

    Please Login or Register  to view this content.
    return only part of the filename i.e 1105? at the moment with out that flter part whcich exists in the above command (in seperate routine) for the filename (F1105.xls) it returns .xls

    ---------- Post added at 08:36 AM ---------- Previous post was at 08:30 AM ----------

    Okay solved it, by placing the month=mid(filename,3,4) in each part of the sub routines. Is their a better way of doing this?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,440

    Re: autofilter macro using variable

    A global variable can mean different things to different people.

    If a variable is shared by subroutines in the same module, Dim it before the first subroutine starts. If it is shared across modules, including Event code, define it as Public.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    07-25-2012
    Location
    aus
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: autofilter macro using variable

    @TMShucks
    ah excellent thanks, can you then call on it with out any special function?
    Last edited by Cutter; 07-30-2012 at 08:05 PM. Reason: Removed whole post quote

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,440

    Re: autofilter macro using variable

    Sure, it's the same as a variable defined within a module. Just don't declare it twice.

  7. #7
    Registered User
    Join Date
    07-25-2012
    Location
    aus
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: autofilter macro using variable

    thanks for that mate. i have another issue now thoguh..again due to pilots being inconsistant, they sometimes use the date format d/m/yyyy, (01-May-2011) or they use 110501. however the latter being just the numbers not a propper date format. i used this code to change the first into the latter but if it encounters the latter it converts it to something different as its just a value techically.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,440

    Re: autofilter macro using variable

    Different question, new thread ... more input.

    Please mark this as solved and start a new thread.

    Thanks, TMS

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: autofilter macro using variable

    @ 86gts

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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