Home > Mobile >  VBA how to find the last empty cell after an active 1
VBA how to find the last empty cell after an active 1

Time:06-22

I want to fill in the time in the next empty cell , but the fucntion End(xlUp) takes me to the last active cell , and the End(xlDown) takes me to the last cell of the chart.

What do I do? Please help me

Here's the code I wrote to find the last cell of column "F" .

Function insertTime()

Range("F").End (xlUp)  = Now()

End Function

example image

CodePudding user response:

If your sheet is empty then it will take to last row. If you have data in F Column then it will take to the last cell. Try below codes

Sub insertTime()
    Cells(Rows.Count, "F").End(xlUp).Offset(1, 0) = Now()
End Sub

CodePudding user response:

Offset() to the rescue: where-ever you are, you can use Offset() to move one cell to the left (Offset(0,-1)), to the right (Offset(0,1)), up (Offset(-1,0)) or down (Offset(1,0)), and obviously you can use other numbers: Offset(1,2), Offset(2,-1), ... are ways to jump around like a horse on a chessboard :-)

For your application, I believe that this (or a similar one) might help you:

Go up and to the right:

Range("F:F").End (xlUp).Offset(0,1)  = Now()

Go down and one deeper:

Range("F1").End (xlDown).Offset(1,0)  = Now()

...

  • Related