i have a range sheet.name("tota").rangeb4:b53
i want when i put some data in this range then it go auto sort "a to z"
thanx
when i go to that sheet
i have a range sheet.name("tota").rangeb4:b53
i want when i put some data in this range then it go auto sort "a to z"
thanx
when i go to that sheet
Use Code-Tags for showing your code :
Please mark your question Solved if there has been offered a solution that works fine for you
If You like solutions provided by anyone, feel free to add reputation using STAR *
Try this:-
Private Sub Worksheet_Change(ByVal Target As Range) Dim lCell As String lCell = ActiveWorkbook.Worksheets("tota").Range("B" & Rows.Count).End(3).Offset(1).Address ActiveWorkbook.Worksheets("tota").Sort.SortFields.Clear ActiveWorkbook.Worksheets("tota").Sort.SortFields.Add Key:=Range("B4"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("tota").Sort .SetRange Range("B4:B53") .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With ActiveWorkbook.Worksheets("tota").Range(lCell).Select End Sub
This would be a litte bit shorter
Private Sub Worksheet_Change(ByVal Target As Range) If Not IsEmpty(Cells(Target.Row, 1)) And Not IsEmpty(Cells(Target.Row, 2)) Then 'this makes sure the sort only happens if A and B have a value comment out if you dont need that Columns("A:B").Sort key1:=Range("A:A"), order1:=xlAscending, key2:=Range("B:B"), order2:=xlAscending, Header:=xlYes 'sorts A and B ascending by A then B End If' this has to be commented out too if you remove the if End Sub
Last edited by TheAnalyticalWolf; 12-06-2016 at 12:25 PM.
Thanx all of u dear
i have a question?
if i sort out automatically data from different sheets at a time
thanx
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks