+ Reply to Thread
Results 1 to 7 of 7

Selecting a range variable in different worksheets within same workbook

  1. #1
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Selecting a range variable in different worksheets within same workbook

    I am having trouble figuring out how to do the following:

    I want to make a range variable ("testrange") that I can use to define a range of non-continuous cells and then use that range variable to select that range of cells in different worksheets within the same workbook.

    I tried the below code (simply coloring cells red), but get an error when I try to select "testrange" after moving to the next worksheet.

    Please Login or Register  to view this content.
    The next worksheet is also supposed to have the same range of cells colored red, but I can only get it to work on the first active sheet.

    I would like to avoid having to repeatedly rebuild the range I want selected each time I move to a different worksheet.

    I will appreciate any help on this.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Selecting a range variable in different worksheets within same workbook

    testrange will be linked to the sheet you define it on, so when you move to the next sheet, it will be trying to select a range on a non-active sheet which would cause the problem. I would suggest something like:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: Selecting a range variable in different worksheets within same workbook

    Thank you for the reply, ragulduy.

    Sadly, the range I am going to be selecting is going to be a whole lot bigger/longer than the example I gave (over 50 non-consecutive cell ranges) and I was planning to build that range using loops and Union.

    My ultimate goal is to use the testrange to periodically consolidate the conditional formatting ranges for 30+ worksheets. Conditional formatting takes up a lot of file size space when there are duplicate rules covering several ranges (inevitably happens when copy-pasting-inserting), but much less so when there is only one instance of the rule covering all the ranges (this would be testrange).

    Thus, given specified row #s and other conditions, testrange is going to have to change in size to fit what I need covered.

    I guess I could try to convert my current dozens of conditional formatting rules to vba code, but I'd rather not if I could help it...
    And wouldn't I still have the range problem...?

  4. #4
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: Selecting a range variable in different worksheets within same workbook

    Now that I think about it, I can just add the rebuilding of the testrange for every single loop through the worksheets. This will likely take a looong time to process (what with loops within loops within loops multiplied by worksheets and conditional formatting rules), but I guess it can't be helped. Better than doing it manually!

    At least now I can move on from this dead end idea of mine thanks to ragulduy explaining why it won't work.

    I will hold out hope that there is a brilliant workaround out there and that I will come upon it some time. Until then, I shall see if there are other ways to reduce the process time or file size.
    Last edited by Monimonika; 08-22-2014 at 01:50 PM.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Selecting a range variable in different worksheets within same workbook

    If the range if the same on all sheets,

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    05-21-2014
    Posts
    92

    Re: Selecting a range variable in different worksheets within same workbook

    Hi shg!

    I actually tried to define the range by string at first, but the string got too long and vba would not recognize the whole string (it truncates at some point). Things got really icky complicated when I tried to break the string into manageable substrings, so I fled from that idea and into the arms of range variables (which apparently do not have such a size limitation as string variables).

    (This was also back when I thought ranges had to be defined by Column Letters and Row #s. I then found out about using Cells, which made it easier to define ranges solely by integers and formulas, as well as to enlarge using counter loops.)

    I think that even if I can use strings to fill in a Range( Cells (row,column), Cells (row, column) ) format, I will still run into the limitation of string length problem.

    Thank you for trying to help, though!

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Selecting a range variable in different worksheets within same workbook

    Then define it as a named range with worksheet scope on each sheet. Then

    Please Login or Register  to view this content.
    Last edited by shg; 08-23-2014 at 10:54 AM.

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Selecting a range variable in different worksheets within same workbook

    Maybe:

    Please Login or Register  to view this content.
    ?

+ 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. [SOLVED] copy common cells and variable range from multiple worksheets to single master workbook
    By tg7384 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-15-2014, 03:05 PM
  2. Copy variable range from variable workbook to variable range on current workbook
    By Locster79 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2013, 10:37 AM
  3. [SOLVED] Selecting range using variable
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-27-2013, 11:33 AM
  4. Selecting a variable range
    By Bill in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-16-2006, 12:45 PM
  5. selecting Variable range
    By katmando in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-18-2006, 04:51 AM

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