+ Reply to Thread
Results 1 to 9 of 9

redefine/resize named range VBA

  1. #1
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    redefine/resize named range VBA

    Hi,

    How can i redefine a named range in VBA?

    I've attached a example workbook: I'm trying to define my named range "prices" based on ticked/non-ticked check boxes. If Check box 1 is ticked the range should be column A:C, check box 2 column F:H, Check box 3 column D,E,I. And of course if multiple check boxes are selected then the all of columns of each "option" should be included in the named range.

    This is how far i've gotten so far

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,487

    Re: redefine/resize named range VBA

    Please Login or Register  to view this content.
    Note how ever your formula will not work if only checkbox 3 is checked due to the non contiguous range.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: redefine/resize named range VBA

    Thanks a lot for your code! Is there no way to make it work with non-contiguous ranges? Just had an idea of copying the "wanted" prices to a new sheet (contiguous or not) and then have dynamic named range (ie using offset()) is that new sheet.

    Do you think that would work? Or is there no way of copying non-contiguous ranges so that they are contiguous (in a new sheet)?

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,487

    Re: redefine/resize named range VBA

    The code works and the named range Prices is updated, both contiguous and non contiguous.

    It is the formula you have based on prices that is not working. Try selecing option 3 only and updating.

    If you copy the range Prices it will paste as a contiguous block.

  5. #5
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: redefine/resize named range VBA

    Well that's kind off my original issue. Don't get me wrong, your code was VERY helpful, but i need to be able to select non-adjacent columns as my named range "prices". Is there anyway of doing this that you know? Doesn't really matter if the code gets messy or if I have to copy my data to a new data and then define "prices" based on the data in that new sheet.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,487

    Re: redefine/resize named range VBA

    the variable rngUsePrices contains a reference to the selected range, whether it's contiguous or not.
    So you can use that to copy the information to another sheet and then do your formula or what ever from there.

  7. #7
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: redefine/resize named range VBA

    Hm.. It's probably just me not understanding what you mean, but i tried changing the last lines to

    Please Login or Register  to view this content.
    Just to see if it would print the all columns even if they were non-contiguous. That didn't work as expected, choosing "option 3" will only print the 2 adjacent columns, leaving out the third column.

    Maybe I have to use a for-loop to extract all the information from rngUsePrices, as all the information SHOULD be in there..? I'm a bit confused as to how the Union() function works, as the union only seems to work if the columns are adjacent..
    Last edited by vizzkid; 04-17-2013 at 06:00 AM.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,487

    Re: redefine/resize named range VBA

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: redefine/resize named range VBA

    I see..

    Well this solves a lot of problems, thank you VERY MUCH (!) and thank you for being so patient

+ 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