ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   sorting (https://www.excelbanter.com/new-users-excel/199315-sorting.html)

abolbashaari

sorting
 
can i sort my data automatically without click on "sort" icon

Gary''s Student

sorting
 
You can have a change event macro perform the sort.
--
Gary''s Student - gsnu200800


"abolbashaari" wrote:

can i sort my data automatically without click on "sort" icon


Bob Phillips[_3_]

sorting
 
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A:C" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

Me.Cells.Sort key1:=Me.Range("A1"), order1:=xlAscending, _
key2:=Me.Range("B1"), order2:=xlAscending, _
heder:=xlYes
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
__________________________________
HTH

Bob

"abolbashaari" wrote in message
...
can i sort my data automatically without click on "sort" icon




abolbashari

sorting
 
What is this code and how does it do and how can i inter my data for sorting
automaticlly

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A:C" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

Me.Cells.Sort key1:=Me.Range("A1"), order1:=xlAscending, _
key2:=Me.Range("B1"), order2:=xlAscending, _
heder:=xlYes
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
__________________________________
HTH

Bob

"abolbashaari" wrote in message
...
can i sort my data automatically without click on "sort" icon





Bob Phillips[_3_]

sorting
 
Do what it says, and change some data column A or B, and see what happens.

--
__________________________________
HTH

Bob

"abolbashari" wrote in message
...
What is this code and how does it do and how can i inter my data for
sorting
automaticlly

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A:C" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

Me.Cells.Sort key1:=Me.Range("A1"), order1:=xlAscending, _
key2:=Me.Range("B1"), order2:=xlAscending, _
heder:=xlYes
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
__________________________________
HTH

Bob

"abolbashaari" wrote in message
...
can i sort my data automatically without click on "sort" icon







abolbashari

sorting
 
i found error finaly .correct header spell in code.


"Bob Phillips" wrote:

Do what it says, and change some data column A or B, and see what happens.

--
__________________________________
HTH

Bob

"abolbashari" wrote in message
...
What is this code and how does it do and how can i inter my data for
sorting
automaticlly

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A:C" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

Me.Cells.Sort key1:=Me.Range("A1"), order1:=xlAscending, _
key2:=Me.Range("B1"), order2:=xlAscending, _
heder:=xlYes
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
__________________________________
HTH

Bob

"abolbashaari" wrote in message
...
can i sort my data automatically without click on "sort" icon








All times are GMT +1. The time now is 06:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com