microsoft_excel:macro_sort
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
microsoft_excel:macro_sort [2020/07/15 09:30] – external edit 127.0.0.1 | microsoft_excel:macro_sort [2021/08/04 14:26] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Microsoft Excel - Macro Sort ====== | ||
- | |||
- | An example showing how to sort a worksheet. | ||
- | |||
- | <code excel> | ||
- | ' Sorts all queries on all sheets. | ||
- | ' Unfortunately, | ||
- | Sub Sort_Queries() | ||
- | |||
- | Dim lastrow_Test1 As Long | ||
- | Dim lastrow_Test2 As Long | ||
- | |||
- | | ||
- | | ||
- | ' Ask user. | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | |||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | |||
- | |||
- | With Workbooks(wb_name) | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_Test1 = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | | ||
- | With .Sheets(" | ||
- | | ||
- | ' Activates the sheet. | ||
- | .Activate | ||
- | | ||
- | | ||
- | ' Update StatusBar. | ||
- | Application.StatusBar = " | ||
- | | ||
- | | ||
- | ' Determine the number of rows. | ||
- | lastrow_Test2 = .Cells(Rows.Count, | ||
- | | ||
- | |||
- | ' Do the sort. | ||
- | With .Sort | ||
- | | ||
- | ' | ||
- | With .SortFields | ||
- | .Clear | ||
- | .Add Key: | ||
- | End With | ||
- | | ||
- | .SetRange Range(" | ||
- | .Header = xlYes | ||
- | .MatchCase = False | ||
- | .Orientation = xlTopToBottom | ||
- | .SortMethod = xlPinYin | ||
- | .Apply | ||
- | | ||
- | End With | ||
- | |||
- | |||
- | ' Select A1. | ||
- | ScrollTo ActiveSheet.name, | ||
- | |||
- | End With | ||
- | | ||
- | End With | ||
- | End Sub | ||
- | |||
- | </ | ||
microsoft_excel/macro_sort.1594805433.txt.gz · Last modified: 2020/07/15 09:30 by 127.0.0.1