Results 1 to 6 of 6

Thread: Does object.Offset have an upper limitation in Range Row increases?

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Location
    Dallas, TX
    Posts
    3

    Does object.Offset have an upper limitation in Range Row increases?

    I have a VBA module I have written for a .DAT file that I am running through Excel.
    The code is working as expected until I run into this section:

    ...
    VB Code:
    1. i = 1
    2. Set sortCell = r1.Cells(i, 20)
    3. Set r1 = ActiveSheet.Range(Cells(1, 1), Cells(A, 20))
    4. Do While i < A
    5.     sortCell.Value = r1.Cells(1, 1).Value & "|" & r1.Cells(1, 5).Value & "|" & r1.Cells(1, 6).Value & "|" & r1.Cells(1, 7).Value & "|" & r1.Cells(1, 8).Value & "|" & r1.Cells(1, 9).Value & "|" & r1.Cells(1, 10).Value & "|" & r1.Cells(1, 11).Value & "|" & r1.Cells(1, 12).Value & "|" & r1.Cells(1, 13).Value & "|" & r1.Cells(1, 14).Value & "|" & r1.Cells(1, 15).Value & "|" & r1.Cells(1, 16).Value & "|" & r1.Cells(1, 17).Value & "|" & r1.Cells(1, 18).Value
    6.     Set sortCell = sortCell.Offset(1, 0)
    7.     Set r1 = r1.Offset(1, 0)  
    8.     i = i + 1
    9. Loop
    ...
    There are 37011 rows in the sheet this month. 37011 is the value of A and is calculated in a previous section.
    When I get to Set r1 = r1.Offset(1, 0) I get a 1004 Application-defined or object-defined error. This occurs in row 28527 of the spreadsheet.
    The application allows sortCell row to get set to 28527 but when it tries to increase the range row from 28526 to 28527, I get the error message.
    I use watch to track the values.
    Has anyone run into this and have any advice?
    thanks

  2. #2
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: Does object.Offset have an upper limitation in Range Row increases?

    you need to add the

    VB Code:
    1. .Activate

    to the offset code to make it work.

    if you are incrementing a row number it would be better to use a counter to do this, or do CurrentRowNumber +1
    if you fail to plan, you plan to fail

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Location
    Dallas, TX
    Posts
    3

    Re: Does object.Offset have an upper limitation in Range Row increases?

    Thanks for the advice but that did not solve it. If I add .activate at the end, I get an object must be declared error message.
    Plus, it had recognized and written to 28526 cells previously so the cells were already active via the ActiveSheet function to declare those cells.

  4. #4
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: Does object.Offset have an upper limitation in Range Row increases?

    Ok,

    why use the offset at all?
    if you put your set into the loop at the start, and your 'i' count is incrementing so doing your offset for you.

    do the same for the r1 range and increment the rows using a counter.

    why i suggested it previously as you were setting a range, so the .activate wouldnt have helped (unless you are cycling through cells real time)

    VB Code:
    1. i = 1
    2. Do While i < A
    3.     Set r1 = ActiveSheet.Range(Cells(1, 1), Cells(A, 20))'increment this using a counter similar to 'i'
    4.     Set sortCell = r1.Cells(i, 20)
    5.     sortCell.Value = r1.Cells(1, 1).Value & "|" & r1.Cells(1, 5).Value & "|" & r1.Cells(1, 6).Value & "|" & r1.Cells(1, 7).Value & "|" & r1.Cells(1, 8).Value & "|" & r1.Cells(1, 9).Value & "|" & r1.Cells(1, 10).Value & "|" & r1.Cells(1, 11).Value & "|" & r1.Cells(1, 12).Value & "|" & r1.Cells(1, 13).Value & "|" & r1.Cells(1, 14).Value & "|" & r1.Cells(1, 15).Value & "|" & r1.Cells(1, 16).Value & "|" & r1.Cells(1, 17).Value & "|" & r1.Cells(1, 18).Value
    6.     i = i + 1
    7. Loop

    trying it like this will rule out an issue with the offset command.
    if you fail to plan, you plan to fail

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Location
    Dallas, TX
    Posts
    3

    Re: Does object.Offset have an upper limitation in Range Row increases?

    Brian,

    Thanks for the kick. After you mention about why use the Offset, I went back and looked at what I was trying to accomplish. I had too many unnecessary variables. The final code, which allows me to create a very nifty looking Subtotal spreadsheet, is:
    VB Code:
    1. j = 1
    2.     For j = 1 To A
    3.     ActiveSheet.Cells(j, 2).Value = ActiveSheet.Cells(j, 1).Value & "|" & ActiveSheet.Cells(j, 6).Value & "|" & ActiveSheet.Cells(j, 7).Value & "|" & ActiveSheet.Cells(j, 8).Value & "|" & ActiveSheet.Cells(j, 9).Value & "|" & ActiveSheet.Cells(j, 10).Value & "|" & ActiveSheet.Cells(j, 11).Value & "|" & ActiveSheet.Cells(j, 12).Value & "|" & ActiveSheet.Cells(j, 13).Value & "|" & ActiveSheet.Cells(j, 14).Value & "|" & ActiveSheet.Cells(j, 15).Value & "|" & ActiveSheet.Cells(j, 16).Value & "|" & ActiveSheet.Cells(j, 17).Value & "|" & ActiveSheet.Cells(j, 18).Value & "|" & ActiveSheet.Cells(j, 19).Value
    4.     ActiveSheet.Cells(j, 5).Value = 1
    5.     Next j

    Thanks for your help.

  6. #6
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: Does object.Offset have an upper limitation in Range Row increases?

    thats what i was aiming for...using a variable count within your range.

    if you fail to plan, you plan to fail

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width