Solved i wnat to automatically sort a when new data is entered

August 13, 2012 at 21:42:21
Specs: Windows Vista
is there a simple way to automatically sort without using macros

See More: i wnat to automatically sort a when new data is entered

Report •

✔ Best Answer
August 22, 2012 at 05:27:39
Try this version:

Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Column = 3 Then
     Columns("A:B").Sort Key1:=Range("B1"), Order1:=xlAscending, Key2:=Range("A1") _
        , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
        False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
        :=xlSortNormal
   End If
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.



#1
August 14, 2012 at 09:17:33
Something has to tell Excel to sort the data after an entry is made, so it's either got to be the user or a macro.

Excel does provide "event driven" macros, so you wouldn't have to manually call the macro, which makes it kind of automatic.

For example, the following code will automatically sort Column A as soon as an entry is made in that columns:

Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Column = 1 Then
     Columns("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
   End If
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
August 21, 2012 at 16:22:45
Sorry for the delay - out of town
This macro works great; however if I have data in col a, b, c How would I sort col b, then col a
i.e. Lastnames and firstnames
Thanks in advnace.

Report •

#3
August 21, 2012 at 18:15:47
Before I can answer your latest question, I would need to know what entry you want to trigger the code.

For example...

Will you be entering data in A then B then C, and then after the data in C is entered, the sort should happen?

In other words, I need to know where (which column) the change will be made that will trigger the sort.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Related Solutions

#4
August 21, 2012 at 19:30:53
column a has first names
column b has last names
col c has a code
after entring the data in col c I would like to sort col b , then a (Lastnames then firstnames)
Thanks

Report •

#5
August 22, 2012 at 05:27:39
✔ Best Answer
Try this version:

Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Column = 3 Then
     Columns("A:B").Sort Key1:=Range("B1"), Order1:=xlAscending, Key2:=Range("A1") _
        , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
        False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
        :=xlSortNormal
   End If
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Ask Question