Computer Science, asked by camron1723, 1 year ago

How to number sort in excel and next number change automatically sort?

Answers

Answered by ck233
0
1. Right click current sheet name in the Sheet Tab bar, and then click the View Code from the right-clicking menu.


2. In the opening Microsoft Visual Basic for Application dialog box, paste the following VBA macro code into the opening window.


VBA: Auto Sort Column in Excel

Private Sub Worksheet_Change(ByVal Target As Range) On Error Resume Next If Not Intersect(Target, Range("B:B")) Is Nothing Then Range("B1").Sort Key1:=Range("B2"), _ Order1:=xlAscending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, _ Orientation:=xlTopToBottom End If End Sub

Note: In the above vba code, B:B means it will auto sort Column B, B1 is the first cell in Column B, B2 is the second cell in Column B, and you can change them based on  your needs.

3. Then go back to the worksheet, when you enter a new number in the Price column or modify any existing prices, the Price column will be automatically sorted in ascending order.

Note: when entering new number in the Price column, you must enter the number in the first blank cell below original numbers. If there are blank cells between new entered number and original numbers as well as blank cells between original numbers, this column won't be sorted automatically.

hope it helps you quickly

Similar questions