+ Reply to Thread
Results 1 to 12 of 12

255 Variable length limit?

  1. #1
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    255 Variable length limit?

    I think there is a limit on the length of a variable? I'm hitting a road bump in a macro where a user chooses a list of worksheets from a userform and then the macro will clear the named ranges on that sheet. And some of the named ranges are grabbing multiple cells and ranges on the sheet, thus getting quite long.

    With some past help here in the forums, this is the script within the userform that will clear all of the range areas for each sheet selected. But i'm finding it fails when the named range gets over 255 characters long.

    example of named range.
    Please Login or Register  to view this content.
    And this part of the script doing the clear.
    Please Login or Register  to view this content.
    Also, separately, I'm wondering if this could be done better where I don't have to loop all of the named ranges for each sheet selected? Can it be reversed to loop the named ranges once and compare them to the Sheet Name and if matched perform the clear? would that be better? There is a likely chance a user will selected multiple worksheets to clear, and there over a 100 named ranges already in workbook.

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

    Re: 255 Variable length limit?

    There is a limit, and it is 255 characters.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: 255 Variable length limit?

    Perhaps a loop like


    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: 255 Variable length limit?

    I think I may have found a possible work around. By 'exporting' the named ranges to a worksheet, the cell value will list the entire length of a named range beyond the 255 string limit.

    I can then analyze that cell value and clear all of the ranges in cell/string.

    My Named Range is actually called "Range_Questionnaire" And references this ranges which is 361 characters long.
    Please Login or Register  to view this content.
    When I tried to analyze that in code earlier, it would fail being in excess of 255 characters.

    But if I have that same range info first set to a cell value, i can analyze the cell contents creating an array of each range separately and then clearing them.

    This is working on a limited test basis and needs to be further improved and also perform a match to the worksheet being selected to clear. But i think its a step in the right direction.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: 255 Variable length limit?

    Did you try the code that I posted?
    With the .ReferToRange property of a Name, there is no reason to set a variable to a Name's .RefersTo string.

  6. #6
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: 255 Variable length limit?

    Quote Originally Posted by mikerickson View Post
    Did you try the code that I posted?
    With the .ReferToRange property of a Name, there is no reason to set a variable to a Name's .RefersTo string.
    Yes, I did try that code and was getting the same/result problem in that a variable over 255 is simply just ignored by Excel. No error or warnings given as if the code just skips right over something over 255 characters in length.

    Can you confirm if that code will clear a large named range over various selected cells/ranges that results in length over 255?

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: 255 Variable length limit?

    What length over 255 are you talking about?

    My code doesn't use any strings so length doesn't apply to any of the part of it.

    I think that you are talking about the character limit for Names. My testing (active sheet name is Sheet1) works when Size = 18, Len(Names("myRange").RefersTo)=225, but fails with size = 19, Len(..)=238

    Please Login or Register  to view this content.
    I wonder if you need a different approach to your problem. If you are creating useless Names.....

    I see two ways to approach this
    1) Avoid using names for this. You could use a UDF that returns the Range object instead of a name.

    2) Sub-Naming. A workaround for long RefersTo strings is to define two (or more) names and then combine them in the definition of your final name

    Name: myNamedRange RefersTo: =Name1,Name2

    In VBA
    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: 255 Variable length limit?

    Thanks again for the help, and I created a short example file to help demonstrate.

    The end goal is here is for the user to select the appropriate workpapers (worksheet) and be able to clear the ranges (essentially the shaded cells). The sample just shows a questionnaire, but the actual workbook has much more then that with information throughout a worksheet they would want to clear to start over.

    On a side note, I had tried a different approach on this looping the cells for the interior color, however it seemed much to counterproductive looping all cells in all worksheets.

    You'll see two buttons on the userform. If you press 'Yes', the code runs but nothing happens because the length of variable in the named range is to large. But the second button/attempt is looking a list of the named ranges values and then processing that.

    But if you were to actually shorten the variables of the named range to only a couple of 'sections' of the shaded areas to something under 255 characters long then the cells would be cleared if you did press 'Yes'.

    Hope that all makes sense, and perhaps I am making this alot harder then it should be.
    Attached Files Attached Files
    Last edited by ptmuldoon; 03-15-2016 at 01:29 PM.

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: 255 Variable length limit?

    I notice that the ranges that you want cleared are located regularly.

    Starting at A18, each Area is 4 rows high and 13 columns wide

    The next Area begins at A25, 7 rows below the first, and the pattern continues.
    If that pattern continues in your actual form, then you could use code like this in your user form

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: 255 Variable length limit?

    Quote Originally Posted by mikerickson View Post
    I notice that the ranges that you want cleared are located regularly.
    Starting at A18, each Area is 4 rows high and 13 columns wide
    Yes, that was just an example. The actual workbook has all different ranges the user would clear throughout each worksheet (I still need to create them though). I think the workbook file has about 70 different worksheets all with different areas the user would potential want to clear. I just used that 1 worksheet as an example and duplicated to show what I was trying to accomplish.

    But do you there is a better way to try and clear various sections of a worksheet. This was the solution I could come up with to work around the character limit.
    Last edited by ptmuldoon; 03-15-2016 at 09:02 PM.

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

    Re: 255 Variable length limit?

    You can union ranges in names:

    inputs1 Refers To =A1:A10

    inputs2 Refers To =C1:D12

    inputs3 Refers To =...

    allInputs Refers To: =inputs1, inputs2, inputs3, ...

    Then in VBA,

    Please Login or Register  to view this content.

  12. #12
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: 255 Variable length limit?

    Try this.
    I notice that there were the three areas in G10, 12 and 14.
    All there rest of the answer areas started in column A AND were merged cells And that the merged cells that started in column A extended past column G


    Can you set up your 70 sheets with these restrictions.
    1) All answer fields involve Merged Cells
    2) All answer fields intersect column G, even though they might not begin in that column.
    2) no other merged cells on the sheet

    If that can be done, set up your 70sheets,
    and then run this macro

    Please Login or Register  to view this content.
    That will set up each answer field as its own named range (scoped to the workSHEET).

    Then the Clear code would look like

    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. Set the limit characters length in a cell
    By lkikl in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-16-2015, 05:37 AM
  2. Replies: 3
    Last Post: 11-21-2012, 03:28 PM
  3. Replies: 3
    Last Post: 12-08-2010, 07:51 AM
  4. place a limit on length of text
    By jcavigli in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2008, 03:21 PM
  5. Is there any limit on command length ?
    By velugu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2007, 03:59 AM
  6. number length limit
    By jhahes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2006, 07:25 PM
  7. Limit text length with inputBox
    By BigDave in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2005, 02:11 PM

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