+ Reply to Thread
Results 1 to 4 of 4

Need Variable Range as an Argument

  1. #1
    Registered User
    Join Date
    10-31-2017
    Location
    United States
    MS-Off Ver
    Microsoft Excel for Mac 2011
    Posts
    2

    Need Variable Range as an Argument

    Hi,

    I tried posting this question on the Microsoft forum and I'm not getting any responses, so I hope you will excuse me for cross-posting here.

    I'm trying to add a step to a macro that I use to clean up data before importing it into a database. I want the macro to select all the data in the open worksheet, then sort it by the first column (header row name is ID) because the data I receive is in reverse chronological order, from newest to oldest.

    My problem is that the amount of data varies from day to day, so I cannot assign a fixed range. When I try to use the CurrentRegion, I get an error that the "Argument is not Optional" (which I gather means that you need an actual concrete value, rather than a variable, as a parameter.) I tried assigning a name to the CurrentRegion range and also counting the resulting range. No luck either way, though that might have been because I didn't get the syntax correct.

    I could just assign a huge random range that would cover the largest amount of data possible, but I know there must be a more straightforward way around this situation and I would like to understand the syntax better. I usually fumble my way through by recording operations and then trying to dissect the VBA, but that has it's limitations. (:

    Here is my code in it's present state:
    Please Login or Register  to view this content.
    Many thanks in advance for any suggestions!

    Pax,
    SME

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need Variable Range as an Argument

    Try this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    10-31-2017
    Location
    United States
    MS-Off Ver
    Microsoft Excel for Mac 2011
    Posts
    2

    Re: Need Variable Range as an Argument

    Hey, that was glorious. Thanks bunches!

    Pax,
    Sr. Miriam Esther

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need Variable Range as an Argument

    You're welcome bunches and thanks for the rep!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Variable array argument
    By panicpgh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-25-2014, 05:56 PM
  2. Can I have a Variable Argument List?
    By XmisterIS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2014, 08:02 AM
  3. [SOLVED] LARGE function with variable K argument
    By andrewc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-26-2013, 05:15 AM
  4. ByRef argument type mismatch vs variable declaration
    By Dturazza in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2013, 09:06 AM
  5. Argument not optional error while passing value of variable between subs
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-30-2010, 05:21 AM
  6. Calling a subroutines with a variable argument at a specific time
    By sumanc_nitr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2010, 04:02 PM
  7. [SOLVED] Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM
  8. Variable as argument in filter range
    By Bert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2005, 07:06 PM

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