+ Reply to Thread
Results 1 to 4 of 4

Stopping A Loop When A Blank Cell Is Reached

  1. #1
    Registered User
    Join Date
    02-05-2006
    Posts
    40

    Question Stopping A Loop When A Blank Cell Is Reached

    Hi All,

    I have the following subroutine from a recorded macro:

    Please Login or Register  to view this content.
    It's doing nothing more than copying data to cells in I14 to P14 and then pasting (autofill) all the data in I14:P14 to row 65 (see screen capture of the spreadsheet below to get a better understanding).

    ScreenCap.JPG

    I would like to remove the restriction of only pasting to the 65th row and have a loop that would allow the user to paste to as many rows as is required until there is no more data to perform an operation on. i.e. make the loop stop once a blank cell is reached in =RC[-6].

    Side note: The macro is using the term =RC[-6] for =C14. What's going on there then?

    Best Regards,

    Aaron
    Last edited by Aaron1978; 09-05-2006 at 05:47 AM.

  2. #2
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    the "=RC[-6]" is a relative reference to cell C14 if the active cell is I14. The R without a bracketed number indicates to the formula to use the same row and the C[-6] indicates to use the column 6 to the left (left indicated by the minus sign. Plus sign would indicate to the right).

    As for the loop, you don't need one. If your data is contiguous you can use column H to indicated how far down to paste your formulas. You can use something like this:

    Please Login or Register  to view this content.
    to replace the code:
    Please Login or Register  to view this content.

    Quote Originally Posted by Aaron1978
    Hi All,

    I have the following subroutine from a recorded macro:

    Please Login or Register  to view this content.
    It's doing nothing more than copying data to cells in I14 to P14 and then pasting (autofill) all the data in I14:P14 to row 65 (see screen capture of the spreadsheet below to get a better understanding).

    Attachment 5332

    I would like to remove the restriction of only pasting to the 65th row and have a loop that would allow the user to paste to as many rows as is required until there is no more data to perform an operation on. i.e. make the loop stop once a blank cell is reached in =RC[-6].

    Side note: The macro is using the term =RC[-6] for =C14. What's going on there then?

    Best Regards,

    Aaron
    ---------------------------------------------------
    ONLY APPLIES TO VBA RESPONSES WHERE APPROPRIATE
    To insert code into the VBE (Visual Basic Editor)
    1. Copy the code.
    2. Open workbook to paste code into.
    3. Right click any worksheet tab, select View Code
    4. VBE (Visual Basic Editor) opens to that sheets object
    5. You may change to another sheets object or the This Workbook object by double clicking it in the Project window
    6. In the blank space below the word "General" paste the copied code.

  3. #3
    Registered User
    Join Date
    02-05-2006
    Posts
    40

    Further problem

    Thanks bud. Your code works with one exception; it only autofills the data down to row 51 even though the data in the H column does down to row 65.

    My code now looks like this:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-05-2006
    Posts
    40
    Sorted it.

    Thanks for all your help.

    Best Regards,

    Aaron

+ 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