+ Reply to Thread
Results 1 to 5 of 5

Creating a Dynamic Range that allows for expanding and contracting

  1. #1
    Registered User
    Join Date
    11-24-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Creating a Dynamic Range that allows for expanding and contracting

    My problem is this. I need to create a VBA macro that will allow me to use Solver. On my spreadsheet I have an array that starts in b12 and will extend to ??15.
    I have figured out how to find the number of columns used with:

    Please Login or Register  to view this content.
    What I can't do is figure out how to name this range so that I can reference it in the solver platform. I tried concatenate but VBA rejected my attempts.
    If it goes for 8 columns it would be "B12:I15" but, the next time it might be 9 so then "B12:J15". I tried "B12:" & lngColumns & "15". I don't believe this worked because lngColumns is returning a number not a letter. I really don't know where to go from here as I have tried many different ways and am simply frustrated.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Creating a Dynamic Range that allows for expanding and contracting

    Hello Mattstudent,

    You don't need to know the column name, just how many columns. Using the Resize method will allow you to expand a Range's rows and columns numerically.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Creating a Dynamic Range that allows for expanding and contracting

    Perhaps something like this?

    Please Login or Register  to view this content.
    Alf

  4. #4
    Registered User
    Join Date
    11-24-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Creating a Dynamic Range that allows for expanding and contracting

    Thanks so much for the quick response. I didn't know about the Resize method. Worked great! Glad I found this forum!

  5. #5
    Registered User
    Join Date
    11-24-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Creating a Dynamic Range that allows for expanding and contracting

    Thanks Alf! I appreciate the response!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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