+ Reply to Thread
Results 1 to 8 of 8

Using offset to select next empty cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-04-2006
    Posts
    151

    Using offset to select next empty cell

    Good Day,

    I am having trouble with a code that would allow me to select the next empty cell. The code is as follows:

    Sheet14.Range("k1").Copy Destination:=Sheet10.Range("a1").End(xlUp).Offset(1, 0)
    It works except for the fact that it starts at cell A2 instead of A1. I have searched and googled, and I know it's probably something really silly that I do not know how to do. Any suggestions?

    Thanks a million.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello NewExcelUser,

    The Offset method takes 2 arguments Row, and Column. Your code says to move 1 row down from A1 and stay in the same column. This why you are going to A2.

    The code suggests that you're appending the source range to the current destination. That would be a logical reason for finding the last row in the destination before copying the source over.

    If you simply want to copy the source to range A1 then use this...

    Sheet14.Range("k1").Copy Destination:=Sheet10.Range("a1")
    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    10-04-2006
    Posts
    151
    Hi Leith,

    Thanks for the insight. I do want to copy the information from one cell to the other, however, need the offset because the information in the cell to be copied changes on a daily bases and I would like to keep track of all the changes. The changes occur once a command button is pressed. Once it is pressed the information is automatically copied to the next worksheet.

    The Offset method takes 2 arguments Row, and Column. Your code says to move 1 row down from A1 and stay in the same column. This why you are going to A2.
    So what would be the code to allow the copied info to begin in cell a1 and work its way down?

    Thank you for your help

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello NewExcelUser,

    Use this...
    Dim LastRow As Long
      LastRow = Sheet10.Cells(Rows.Count, "A").End(xlUp).Row
      If LastRow > 1 Then LastRow = LastRow + 1
      Sheet14.Range("k1").Copy Destination:=Sheet10.Cells(LastRow, "A")
    Sincerely,
    Leith Ross

  5. #5
    Forum Contributor
    Join Date
    10-04-2006
    Posts
    151
    Hi Leith,

    Thank you for your reply.

    The code copies the cell just fine, but does not offset to the next row. It just copies over the previous entry.

    Thanks again.

  6. #6
    Forum Contributor
    Join Date
    09-28-2006
    Posts
    122

    try this

    the problem occurs if the column begins empty. the code will return a 1 as the initial answer and then every answer thereafter will be 1 so it never increments itself.

    the following code will do as you wish but the list will start from row 2 downwards

    let me know how you go

    code=
    Dim LastRow As Long
    LastRow = Sheet10.Cells(Rows.Count, "A").End(xlUp).Row
    If LastRow >= 1 Then LastRow = LastRow + 1
    Sheet14.Range("k1").Copy Destination:=Sheet10.Cells(LastRow, "A")

+ 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