Hello all!
I have the following code that auto-sorts my table based on a value in column F. Once sorted, the cursor goes to the bottom of the table. How would I change this code to force the cursor to "follow" the cell in which data was last entered after the sort? The cell is dynamic because of the sort, and not static.
Thanks in advance,
LBinGA
I have the following code that auto-sorts my table based on a value in column F. Once sorted, the cursor goes to the bottom of the table. How would I change this code to force the cursor to "follow" the cell in which data was last entered after the sort? The cell is dynamic because of the sort, and not static.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim finalRow As Integer
Dim i As Integer
Dim erow As Long
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Range("f:f").Select
Range("b2").Sort Key1:=Range("f2"), Order1:=xlDescending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
If Cells(erow - 1, 1).Offset(0, 1) = "" Then
Cells(erow - 1, 1).Offset(0, 1).Select
Else
Cells(erow, 1).Select
End If
finalRow = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1:A" & finalRow).EntireRow.AutoFit
For i = 2 To finalRow
If Range("A" & i).EntireRow.RowHeight < 27 Then
Range("A" & i).EntireRow.RowHeight = 27
If Range("D" & i).EntireRow.RowHeight < 27 Then
Range("D" & i).EntireRow.RowHeight = 27
End If
End If
Next i
On Error Resume Next
End Sub
Thanks in advance,
LBinGA
Last edited: