Quantcast
Channel: プログラミング
Viewing all articles
Browse latest Browse all 8335

VBA:ソート(上順並べ替え) - sannpurazu’s diary

$
0
0


Sub sort2()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim col As Integer
    Dim rng As Range

    ' シートを指定(必要に応じて変更)
    Set ws = ThisWorkbook.Sheets(1)
    
    ' データの最終行を見つける
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    ' 10列(AからJまで)を順番に処理
    For col = 1 To 10
        ' データ範囲を設定(最初の行から最終行まで)
        Set rng = ws.Range(ws.Cells(1, col), ws.Cells(lastRow, col))
        
        ' 範囲を昇順に並べ替え
        rng.Sort Key1:=rng, Order1:=xlAscending, Header:=xlNo
    Next col

    ' 完了メッセージ
    MsgBox "全ての列を昇順に並べ替えました!", vbInformation
End Sub


Viewing all articles
Browse latest Browse all 8335

Trending Articles