Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
VBA function to define name in a worksheet
I'm looking for a way to use a VB function to define a named range and alter
the quantity of cells within the named range. I recorded a macro defining a named range from the "Insert" menu so I could get the VB code. Running a Sub using this code works fine, but I need to run it by calling a function. Below is what I've done. The Sub selectRange_SpareCopy achieves the result I want to get from the function, so I included it as an example. Function selectRange(rangeName, sheet_RowColumn) 'Called by the selectSheetRange Sub ActiveWorkbook.Names.Add Name:="rangeName", RefersToR1C1:= _ "=sheet_RowColumn" End Function Sub selectSheetRange() 'Give range (A1:A7) on Sheet 1 the name "RangeOne" Call selectRange("RangeOne", "Sheet1!R1C1:R7C1") End Sub Sub selectRange_SpareCopy() 'I've kept this here because this Sub works, and the result I get from this _ is the result I want to achieve with the selectRange function ActiveWorkbook.Names.Add Name:="RangeOne", RefersToR1C1:="=Sheet1!R1C1:R7C1" Range("A1").Select End Sub I imagine the main problem will be the lack of DIM as .... and Set rangeName As.... but despite all my experimenting I just don't know what to set these up as. Could anyone help me please? Thank you Regards, Clinton |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
can I define validation range by function? | Excel Worksheet Functions | |||
Define Names Embedded in worksheet | Excel Discussion (Misc queries) | |||
User define function | Excel Discussion (Misc queries) | |||
How to Define a named Formula at the Worksheet level? | Excel Worksheet Functions | |||
How to take the worksheet name as a variable(Label/Define) in a fo | Excel Worksheet Functions |