Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Jay Somerset
 
Posts: n/a
Default Worksheet Cell Range Name within VB Subroutine

How does one refer to a named area in a worksheet from within a VB macro
subroutine? I know how to refer to a selection, but not a block of cells
that has been named using the Insert|Name|Define dialog.

Example: I have a 3x3 block of cells named AA. How can I refer to the
individual cells within AA [e.g. AA(1,2)] within the VB coding of a macro
(subroutine)? How can I make the name AA visible within the subroutine, and
define it a s 3x3 array?

Thanks.
--
Jay.
(remove dashes for legal email address)
  #2   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student
 
Posts: n/a
Default Worksheet Cell Range Name within VB Subroutine

A named area is just a range with a name associated with it:

Sub name_it()
Dim n As Name
Dim r As Range
Dim s As String

For Each n In ThisWorkbook.Names
MsgBox (n.Name)
s = Range(n).Address
MsgBox (s)
Next n

End Sub

n behaves like a string. You can loop until you have the right name and then
SET r=Range(n) and use r like any other range, use all the usual methods
like Clear, use Offsets, Select, etc.
--
Gary's Student


"Jay Somerset" wrote:

How does one refer to a named area in a worksheet from within a VB macro
subroutine? I know how to refer to a selection, but not a block of cells
that has been named using the Insert|Name|Define dialog.

Example: I have a 3x3 block of cells named AA. How can I refer to the
individual cells within AA [e.g. AA(1,2)] within the VB coding of a macro
(subroutine)? How can I make the name AA visible within the subroutine, and
define it a s 3x3 array?

Thanks.
--
Jay.
(remove dashes for legal email address)

  #3   Report Post  
Posted to microsoft.public.excel.misc
paul
 
Posts: n/a
Default Worksheet Cell Range Name within VB Subroutine

if its named AA the vb name is range("AA")
--
paul
remove nospam for email addy!



"Gary''s Student" wrote:

A named area is just a range with a name associated with it:

Sub name_it()
Dim n As Name
Dim r As Range
Dim s As String

For Each n In ThisWorkbook.Names
MsgBox (n.Name)
s = Range(n).Address
MsgBox (s)
Next n

End Sub

n behaves like a string. You can loop until you have the right name and then
SET r=Range(n) and use r like any other range, use all the usual methods
like Clear, use Offsets, Select, etc.
--
Gary's Student


"Jay Somerset" wrote:

How does one refer to a named area in a worksheet from within a VB macro
subroutine? I know how to refer to a selection, but not a block of cells
that has been named using the Insert|Name|Define dialog.

Example: I have a 3x3 block of cells named AA. How can I refer to the
individual cells within AA [e.g. AA(1,2)] within the VB coding of a macro
(subroutine)? How can I make the name AA visible within the subroutine, and
define it a s 3x3 array?

Thanks.
--
Jay.
(remove dashes for legal email address)

  #4   Report Post  
Posted to microsoft.public.excel.misc
Jim May
 
Posts: n/a
Default Worksheet Cell Range Name within VB Subroutine

How does one refer to a named area in a worksheet from within a VB macro
subroutine?
Having named B4:D6 MyNamedRange

Range("MyNamedRange").select

How can I refer to the individual cells within AA [e.g. AA(1,2)] within the
VB coding of a macro (subroutine)?

Set MyRng = Range("MyNamedRange")
MyRng(7).select <<< would select the row 3 column 1 of the 3 X 3 block
B4:D6



"Jay Somerset" wrote in message
...
How does one refer to a named area in a worksheet from within a VB macro
subroutine? I know how to refer to a selection, but not a block of cells
that has been named using the Insert|Name|Define dialog.

Example: I have a 3x3 block of cells named AA. How can I refer to the
individual cells within AA [e.g. AA(1,2)] within the VB coding of a macro
(subroutine)? How can I make the name AA visible within the subroutine,
and
define it a s 3x3 array?

Thanks.
--
Jay.
(remove dashes for legal email address)



  #5   Report Post  
Posted to microsoft.public.excel.misc
Witch-Doctor
 
Posts: n/a
Default Worksheet Cell Range Name within VB Subroutine

On Sat, 04 Feb 2006 19:33:22 -0500, Jay Somerset
wrote:

How does one refer to a named area in a worksheet from within a VB macro
subroutine? I know how to refer to a selection, but not a block of cells
that has been named using the Insert|Name|Define dialog.

Example: I have a 3x3 block of cells named AA. How can I refer to the
individual cells within AA [e.g. AA(1,2)] within the VB coding of a macro
(subroutine)? How can I make the name AA visible within the subroutine, and
define it a s 3x3 array?

Thanks.


The worksheet names are available within a VB macro. Try using...
Range("name").Cells(i, j).Value to refer to the (i,j) member of an
array (cell range) to which the name "name" has been assigned on the
worksheet.




  #6   Report Post  
Posted to microsoft.public.excel.misc
Witch-Doctor
 
Posts: n/a
Default Worksheet Cell Range Name within VB Subroutine

On Sat, 04 Feb 2006 19:33:22 -0500, Jay Somerset
wrote:

How does one refer to a named area in a worksheet from within a VB macro
subroutine? I know how to refer to a selection, but not a block of cells
that has been named using the Insert|Name|Define dialog.

Example: I have a 3x3 block of cells named AA. How can I refer to the
individual cells within AA [e.g. AA(1,2)] within the VB coding of a macro
(subroutine)? How can I make the name AA visible within the subroutine, and
define it a s 3x3 array?

Thanks.


The worksheet names are available within a VB macro. Try using...
Range("name").Cells(i, j).Value to refer to the (i,j) member of an
array (cell range) to which the name "name" has been assigned on the
worksheet.


--
Jay.
(remove dashes for legal email address)
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
need to Copy or Move to active cell from specified range kaream Excel Discussion (Misc queries) 2 December 14th 05 08:12 AM
checking that cells have a value before the workbook will close kcdonaldson Excel Worksheet Functions 8 December 5th 05 04:57 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM
name of another worksheet in cell for reference Tom A Johnson Excel Worksheet Functions 2 November 11th 04 11:28 PM


All times are GMT +1. The time now is 03:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"