pass variable to macro?

pollira
07-02-2001, 08:21 AM
hi,
is there any way to pass a variable (i.e. a parameter) to a macro?

i have a sorting macro which i want to assign to multiple different buttons. each button would sort based on a different key. i want the button to pass the proper sorting key (i.e. column) to the macro. that way i don't need to have multiple different macros.
is there any way to do this? i couldn't find any mention of it in the vb help files.

thanks

mdobs
07-02-2001, 06:00 PM
You could have each button call your sorting macro and pass the variable using a cell, subroutine, or function (probably other ways). The macro that executes when the button is clicked should look something like this.
Sub sort_key_column_three()
'assign the column number to a variable
col_num = 3
'call your sort macro and pass the column number
Call sort_macro_name(col_num)
End Sub

Sub sort_macro_name(column_number)
dim key_range as range
set key_range = range.columns(column_number)
selection.sort
key1:= key_range .....
end sub
The computer I'm using doesn't have excel so I may have left out something. Hope this helps.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum