Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Auto sort ascending

  Asked By: Jose    Date: Mar 10    Category: MS Office    Views: 755
  

How auto ascending sort can be made?
I need it for two column Col A & B
The user will put data in cells of col A & B
After entering data in cell B, when the user will press enter, the
data should be sorted in ascending order based on col A and to
expand the selection to column B.
I reocrded a macro to do this but it has certain problems

1. THe range is fixed
2. It doesnot run automatically as I stated earlier.

Sub sortasc()

Range("A2:B8").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select
End Sub

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Wilfred Young     Answered On: Mar 10

Don't use Select or Selection, just attach the sort  directly to the range.
And try "A2" instead of "A2:B8" to allow Excel to select the range
dynamically.

To get the auto  sort, you will need to call the subroutine from the
Worksheet's Change event. To stop it happening on every worksheet change,
you'll need to limit it to changes to the B column. The If statement you
want for this is:

If (Not Intersect(Target, Columns("B")) Is Nothing) Then
Call SortAsc
End If

It's fun to try, but I bet you turn it off pretty quickly. :-)

 
Answer #2    Answered By: William Bouchard     Answered On: Mar 10

I found the solution
Code is
By rhe time the message is posted, I found the solution.

 
Answer #3    Answered By: Jean Bell     Answered On: Mar 10

you can find te solution through example at ozgrid.com. It worked fine with me.

 
Didn't find what you were looking for? Find more on Auto sort ascending Or get search suggestion and latest updates.




Tagged: