Created
December 11, 2018 04:06
-
-
Save aoshiman/15e2bc307aa571d6d8c97c77d32792ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' | |
' | |
'----------------------------------------------------------------- | |
' 手動で選択した範囲をボタンが設置されている列をKeyとして | |
' 並び替えを実施。ボタン名がASCならば昇順、DESCなら降順で並び替え | |
'----------------------------------------------------------------- | |
Sub ボタンの位置で並べ替え_Click() | |
Dim wCurrCell As String | |
Dim wBtn As String | |
Dim wOrder As Variant | |
On Error Resume Next | |
wBtn = (ActiveSheet.Buttons(Application.Caller).Text) | |
If wBtn = "ASC" Then | |
wOrder = xlAscending | |
Else | |
wOrder = xlDescending | |
End If | |
wCurrCell = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Address | |
With ActiveSheet | |
.Sort.SortFields.Clear | |
.Sort.SetRange .Range(Selection.Address(ColumnAbsolute:=False, RowAbsolute:=False)) | |
.Sort.SortFields.Add Key:=.Range(wCurrCell), Order:=wOrder, DataOption:=xlSortTextAsNumbers | |
.Sort.Header = xlNo | |
.Sort.MatchCase = False | |
.Sort.SortMethod = xlPinYin | |
.Sort.Orientation = xlTopToBottom | |
.Sort.Apply | |
End With | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment