+ Reply to Thread
Results 1 to 4 of 4

Reliable way to increase size of range

  1. #1
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Reliable way to increase size of range

    Hello everyone,

    I am finding that I use a lot of .end(xlup / xldown) in my code nowadays to increase the size of a range when the exact length of a list is variable.

    I tend to do this:

    Please Login or Register  to view this content.
    This method gives me the right range address in the immediate window every time (I type ?range("a1","c" & cells(200,1).end(xlup).row).address and it gives me the correct range of cells without fail). I can even reverse it and say:

    Please Login or Register  to view this content.
    this one is prone to the obvious downfalls, namely that if the range in A1 only contains one entry, it returns the entire colA as the address!

    Here's the thing, when I run the sub from the button on my worksheet, both of these methods fail SOMETIMES (not always). I am asking if anyone knows both why, and whether there are any better ways to capture a list of variable size (from 1 item plus header, to 199 items plus header)?

    I have done some testing and the above codes both fail seemingly randomly. I tested with lists = 1,2,25,100 items and there isn't a pattern i can find!


    extra detail (just in case any of it is important):

    for the sub, screenupdating = false. The sub populates the list, starting at row 3 with a header row at row 2. The sub then uses the MyRange variable to resize a range on a new workbook (workbook.add) and moves the values over (NewRange.value = Myrange.value).
    The result I was getting which prompted me to start this thread was that I had two items in the list. Using the above "xlup" code example the result in the new book would be that the contents of row 1 (a title, not needed) and row 2 (the column headers) was all that was showing and the two list items were not present.

    If there is any extra information i can provide, i will gladly do so
    IF("helping me", "thanks", "need more detail?")

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Reliable way to increase size of range

    I notice you have no worksheet/workbook references in the posted code.

    That means the code will refer to the active worksheet/workbook which might not be what you intend the code to refer to.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    08-23-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Reliable way to increase size of range

    Thank you for the reply,

    In fact my code looks like this:

    Please Login or Register  to view this content.
    Since I am soon going to be working with a new sheet that the sub has created, i thought it best to be explicit with the workbook and sheet that i was working with

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Reliable way to increase size of range

    You haven't specified a sheet for the Cells property. You need to do that.

+ 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. Low and High Range using lookup function not reliable
    By KINGOFTW in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-03-2015, 07:01 AM
  2. Increase size of checkbox
    By siobeh in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-01-2014, 07:04 AM
  3. Increase size of an InputBox
    By techteam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2011, 11:28 AM
  4. AUTOFILTER causes the file size to increase
    By aca in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-11-2011, 11:33 AM
  5. [SOLVED] File Increase in size
    By Martinj in forum Excel General
    Replies: 7
    Last Post: 11-07-2005, 10:10 AM
  6. [SOLVED] how to increase size of diagram lines?
    By Christoph Strobelt [Bt] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2005, 05:05 AM
  7. File size increase
    By Bill Clark in forum Excel General
    Replies: 1
    Last Post: 01-28-2005, 03: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