ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Naming a range (https://www.excelbanter.com/excel-programming/299932-naming-range.html)

Andrew B[_2_]

Naming a range
 
Hi
I would like to define a range like this:
rnga = Range("D61:D96", "D101:D136", "D141:D176").

So I can use it in a spreadsheet formula such as this formula typed into
cell D40:

[D40] = STDEVP(rnga)

I know I can use INSERT - NAME - DEFINE to define rnga but I would like
to be able to do this through VBA.

Is this possible ?

Thanks in advance

Andrew Bourke





Alan Beban[_2_]

Naming a range
 
Sheets("whatever").Range("D61:D96, D101:D136, D141:D176").Name = "rnga"

Alan Beban

Andrew B wrote:

Hi
I would like to define a range like this:
rnga = Range("D61:D96", "D101:D136", "D141:D176").

So I can use it in a spreadsheet formula such as this formula typed into
cell D40:

[D40] = STDEVP(rnga)

I know I can use INSERT - NAME - DEFINE to define rnga but I would like
to be able to do this through VBA.

Is this possible ?

Thanks in advance

Andrew Bourke





Robin Hammond[_2_]

Naming a range
 
Andrew,.

the simplest way for you to figure this one out would be to use the macro
recorder. Here's a long winded version.

Sub NameRange()

Dim rngA As Range

Set rngA = Sheets(1).Range("D61:D96")
Set rngA = Union(rngA, Sheets(1).Range("D101:D136"))
Set rngA = Union(rngA, Sheets(1).Range("D141:D176"))

Sheets(1).Names.Add Name:=Sheets(1).Name & "!" & "RangeA", _
RefersToR1C1:=rngA

End Sub

Robin Hammond
www.enhanceddatasystems.com


"Andrew B" wrote in message
u...
Hi
I would like to define a range like this:
rnga = Range("D61:D96", "D101:D136", "D141:D176").

So I can use it in a spreadsheet formula such as this formula typed into
cell D40:

[D40] = STDEVP(rnga)

I know I can use INSERT - NAME - DEFINE to define rnga but I would

like
to be able to do this through VBA.

Is this possible ?

Thanks in advance

Andrew Bourke








All times are GMT +1. The time now is 07:32 AM.

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