Automatically updating the Last Cell reference

  • Hi,


    I think this is a fairly straight forward problem but I can't figure it out. I am using VBA to copy data, cell-by-cell from one sheet to another. One of the sheets continuously updates while the other sheet records all of the data. I have been figuring out how to find the last cell so that vba will automatically find where it has to put the data.


    This is my code for finding the last cell:

    Code
    LastRow = Sheets("Data by Rows").Range("A65536").End(xlUp).Row
    Cells(LastRow, 1).Select
    LastColumn = ActiveCell.End(xlToRight).Column
    LastCell = Cells(LastRow, LastColumn).Address


    This is a bit roundabout, but each set of data is copied on a different row, but as I said its coping cell-by-cell, across the columns in a row, so this is the easiest way I figured to do it.


    My problem is that I can't figure out how to continuously update LastCell after it copies each cell. This is an example of the copying code:


    Code
    Cells(LastRow + 1, 2) = Application.VLookup("X Velocity", Range("VelocityParameters"), 2, False)
    Range(LastCell).Offset(0, 1) = Application.VLookup("Y Velocity", Range("VelocityParameters"), 2, False)
    Range(LastCell).Offset(0, 1) = Application.VLookup("Angle", Range("VelocityParameters"), 2, False)


    NB. the first line finds the new row in which to place the new data set


    Ideally, I'd like LastCell to automatically update so I don't have to kept telling it where the data needs to go.


    Any advice would be much appreciated.
    Thanks in advance.

  • Re: Automatically updating the Last Cell reference


    Hi


    Try adding a line


    Lastcell = Range(LastCell).Offset(0, 1).address
    between the last 2 code lines in the second code snip you have provided.



    Tony

  • Re: Automatically updating the Last Cell reference


    I would have to do that after every reference to LastCell I make won't I? They are 30 odd cells of data to transfer so is there any way of avoiding having to do it every time.
    Thanks

  • Re: Automatically updating the Last Cell reference


    Jaclyn


    Are these outputs going to a consistent column? So the first output will go to column B, the next to C etc.


    Are you cycling through a list of 30 odd items that you are looking up and putting the results into contiguous columns across the rows? If so then you could put all that into a loop, and use offset from the first cell in the row. You know what that is, so it should be pretty easy.



    Tony

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!