EXCEL VBA按鍵自動排序問題?

2015-08-28 1:30 pm
http://www.FunP.Net/814392

請教以上使用VBA按鍵自動排序,C欄縣市如何設定由北至南排序,郵遞區號已提供於測試檔。另AF欄排序該如何修正為「高>中>低」,因目前排序為「高>低>中」,以上求解~~~~~~~~~非常感謝!!!!

回答 (2)

2015-08-29 8:54 am
✔ 最佳答案
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 遞減排序

'各縣市順序自行去調整~
2015-08-29 12:42 am
頁面設計請使用單一儲存格不使用合併
選取縣市..右鍵...排序...自訂排序...順序(新增一個縣市順序清單)接下來用錄製巨集方式取得程序再來修改


收錄日期: 2021-05-04 01:40:10
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20150828053039AAzx1vU

檢視 Wayback Machine 備份