Need help with adding a range name
i hard coded the variable, but see if this will work:
Sub test()
Dim firstrownum As Long
firstrownum = 6
With Worksheets("Sheet2").Cells(firstrownum, 1)
ActiveWorkbook.Names.Add Name:="database", RefersTo:=Range(.Address, _
.End(xlDown).End(xlToRight))
End With
End Sub
--
Gary
"Bob" wrote in message
...
I select a range by using the following code:
Worksheets(Sheet2Name).Cells(Sheet2FirstRowNum, 1).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Is there a way I can "convert" the aforementioned selected range (which can
vary) into the required R1C1 format so that I end up with something like this:
ActiveWorkbook.Names.Add Name:="Database", RefersToR1C1:= _
"=Worksheets(Sheet2Name)!R2C1:R18C11"
Any help would be greatly appreciated. Thanks.
|