Hi!
I have found two old posts that have code that sort of work for my needs, but neither matches entirely. Can anyone help me modify either of these to fit my needs?
Problem: I want to auto sort a worksheet automatically by column A after a new entry has been added. I need the sort to move columns A through I even if a column is left blank. I would prefer it do this after the last entry in the row is made instead of column A or even on saving the workbook.
This code works, but moves the row immediately after data is entered into column A making the user have to scroll up and find it before being able to complete the row entry:
This code kind of works, but it doesn't allow for any blank entries. Sometimes there will be a blank in one of the columns. But I like that it moves the row after the data is entered in all columns.
Thanks in advance for any help - it is greatly appreciated!
I have found two old posts that have code that sort of work for my needs, but neither matches entirely. Can anyone help me modify either of these to fit my needs?
Problem: I want to auto sort a worksheet automatically by column A after a new entry has been added. I need the sort to move columns A through I even if a column is left blank. I would prefer it do this after the last entry in the row is made instead of column A or even on saving the workbook.
This code works, but moves the row immediately after data is entered into column A making the user have to scroll up and find it before being able to complete the row entry:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long
If Target.Column = 1 Then
LR = Range("A" & Rows.Count).End(xlUp).Row
Application.EnableEvents = False
Range("A1:I" & LR).Sort Key1:=Range("A2"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Application.EnableEvents = True
End If
End Sub
This code kind of works, but it doesn't allow for any blank entries. Sometimes there will be a blank in one of the columns. But I like that it moves the row after the data is entered in all columns.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If WorksheetFunction.CountA(Cells(Target.Row, 1).Resize(1, 9)) = 9 And Target.Column < 10 Then
Application.EnableEvents = False
Range("A1", Cells(Rows.Count, 9).End(xlUp)).Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Application.EnableEvents = True
End If
End Sub
Thanks in advance for any help - it is greatly appreciated!