ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro To Create Other Macros And Buttons (https://www.excelbanter.com/excel-programming/286962-macro-create-other-macros-buttons.html)

Robert P. Stearns

Macro To Create Other Macros And Buttons
 
I create Excel spreadsheets to track all kinds of sports statistics. I would
like to programmatically place two buttons above each column that contains
data to sort based on that column. This gives the users a quick way to sort.
So, in A1 I'd have a (+) button and a (-) button. The actual data would
start in A2. The buttons would run macros to sort ascending (+) or sort
descending (-). This is a tedious process manually. I need to write macros
then I need to place buttons then assign macros. I would like to define the
macros along with the buttons inside another macro.

Is this possible?

This is a sample of the macros that I currently use:

Sub d_kick_td_asc()
Call rank("AF6", "A")
End Sub

Sub d_kick_td_desc()
Call rank("AF6", "D")
End Sub

Function rank(col, upd)
If (col = "") Then col = "A6"
If (upd = "A" Or upd = "a") Then
upd = xlAscending
Else
upd = xlDescending
End If
*Range("all").Select
Selection.Sort Key1:=Range(col), Order1:=upd, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
ActiveWindow.LargeScroll ToRight:=-1
ActiveWindow.LargeScroll Down:=-6
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 6
Range(col).Select
End Function

*Note: "all" has been previously defined.




All times are GMT +1. The time now is 01:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com