✔ 最佳答案
Private Sub CommandButton1_Click()
TT$ = "基隆市,台北市,新北市,宜蘭縣,宜蘭市,新竹縣,新竹市,桃園市,苗栗縣,苗栗市," & _
"台中市,彰化縣,彰化市,南投縣,南投市,雲林縣,嘉義縣,嘉義市,台南市,高雄市," & _
"屏東縣,屏東市,台東縣,台東市,花蓮縣,花蓮市,澎湖縣,金門縣,連江縣,南海諸島"
Call 排序(CommandButton1.Caption, 1, TT)
End Sub
Private Sub CommandButton2_Click()
Call 排序(CommandButton2.Caption, 2, "")
End Sub
Private Sub CommandButton3_Click()
Call 排序(CommandButton3.Caption, 2, "")
End Sub
Private Sub CommandButton4_Click()
TT$ = "高,中,低"
Call 排序(CommandButton4.Caption, 1, TT)
End Sub
Private Sub CommandButton5_Click()
Call 排序(CommandButton5.Caption, 2, "")
End Sub
Private Sub CommandButton6_Click()
Call 排序(CommandButton6.Caption, 2, "")
End Sub
Private Sub CommandButton7_Click()
Call 排序(CommandButton7.Caption, 2, "")
End Sub
Sub 排序(SortStr$, xOrd, SortList$)
Dim MH, NN&
MH = Application.Match(SortStr, Rows(2), 0)
If IsError(MH) Then Exit Sub
If SortList <> "" Then
Application.AddCustomList ListArray:=Split(SortList, ",")
NN = Application.CustomListCount
End If
[B4:AY100].Sort Key1:=Cells(4, MH), Order1:=xOrd, Header:=xlNo, OrderCustom:=NN + 1
If NN > 0 Then Application.DeleteCustomList ListNum:=NN
End Sub
'===========================
'xOrd = 1 遞增排序
'xOrd = 2 遞減排序
'各縣市順序自行去調整~