View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
hjc hjc is offline
external usenet poster
 
Posts: 17
Default named range in macro call

Is there a way to pass a named range (or even an unnamed block of cells) into
a macro?

I have written a macro that I want to use for several different ranges of
data. I have created multiple buttons that each call the macro, but I cannot
seem to find the right syntax to pass in the range of data that I want the
macro to use for each button. All I can do is to pass in the row and column
numbers that define the upper left and lower right corners of the data range,
as follows:

Private Sub CommandButton1_Click()
' Call Macro1(UpperLeftRow, UpperLeftCol, LowerRightRow, LowerRightCol)
Call Macro1(16, 9, 40, 35)
End Sub

Private Sub CommandButton2_Click()
Call Macro1(51, 9, 75, 35)
End Sub

etc.

If possible, I would like to be able to specify named ranges instead, so
that I don't have to edit the code for all the buttons if I add, delete or
move rows or columns. Is there a way to do this?

Thanks!
hjc