原來我離excel這麼遠
公司來了一位excel很強的財務主管,建議我公司全面換成office 365,這樣就能擁有office 365專屬的函式,例如 sort。
可惜公司不會全部(含各廠)升級到o365;沒關係,我們還有vba。
(一)先開啟開發人員功能(方便執行)或是按下 Alt+F11 直接叫出vba來。
![](https://i0.wp.com/kafeiou.pw/wp-content/uploads/2024/09/image-5.png?resize=860%2C676&ssl=1)
(二)寫VBA
![](https://i0.wp.com/kafeiou.pw/wp-content/uploads/2024/09/image-6.png?resize=821%2C538&ssl=1)
Sub SortData()
Range("A:G").Sort , _
Key1:=Range("E2"), Order1:=xlAscending, _
Key2:=Range("D2"), Order2:=xlDescending, _
Header:=xlYes
End Sub
![](https://i0.wp.com/kafeiou.pw/wp-content/uploads/2024/09/image-8.png?resize=737%2C225&ssl=1)
(三)打開Excel表格,輸入ALT+F8執行巨集(VBA)
即可進行排序
![](https://i0.wp.com/kafeiou.pw/wp-content/uploads/2024/09/image-7.png?resize=640%2C222&ssl=1)