PC Review


Reply
Thread Tools Rate Thread

Assigning named range to a 2-dimensional array

 
 
=?Utf-8?B?Qm9i?=
Guest
Posts: n/a
 
      4th Sep 2007
I have a named range ("AdjHoursLookup") that currently occupies 12 cells (3
rows x 4 columns), but the number of cells will vary over time.

Is it possible to assign the named range to a 2-dimensional array? When I
excute the following two lines of code, for example, I get an "object
required" error message.

Dim AdjHoursArray As Range
Set AdjHoursArray = Range("AdjHoursLookup").Value

Any help would be greatly appreciated. Thanks.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Qm9i?=
Guest
Posts: n/a
 
      4th Sep 2007
I just discovered that by removing ".Value", it fixes the "object required"
error message problem.

But now I have another issue. Since the size of the named range will vary
over time, is there a way I can determine the number of non-blank elements in
the array?

Thanks again for any help.


"Bob" wrote:

> I have a named range ("AdjHoursLookup") that currently occupies 12 cells (3
> rows x 4 columns), but the number of cells will vary over time.
>
> Is it possible to assign the named range to a 2-dimensional array? When I
> excute the following two lines of code, for example, I get an "object
> required" error message.
>
> Dim AdjHoursArray As Range
> Set AdjHoursArray = Range("AdjHoursLookup").Value
>
> Any help would be greatly appreciated. Thanks.
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      4th Sep 2007
Dim AdjHoursArray As Range
Set AdjHoursArray = Range("AdjHoursLookup")
msgbox application.counta(adjhoursarray) & vblf & adjhoursarray.cells.count

=counta() will count all the formulas and constants that are in that
range--including formulas that evaluate to "" (like =if(a1=5,"ok",""))



Bob wrote:
>
> I just discovered that by removing ".Value", it fixes the "object required"
> error message problem.
>
> But now I have another issue. Since the size of the named range will vary
> over time, is there a way I can determine the number of non-blank elements in
> the array?
>
> Thanks again for any help.
>
> "Bob" wrote:
>
> > I have a named range ("AdjHoursLookup") that currently occupies 12 cells (3
> > rows x 4 columns), but the number of cells will vary over time.
> >
> > Is it possible to assign the named range to a 2-dimensional array? When I
> > excute the following two lines of code, for example, I get an "object
> > required" error message.
> >
> > Dim AdjHoursArray As Range
> > Set AdjHoursArray = Range("AdjHoursLookup").Value
> >
> > Any help would be greatly appreciated. Thanks.
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?cDQ1Y2Fs?=
Guest
Posts: n/a
 
      4th Sep 2007
Note that te title of this thread seems at odds with the code quoted;
Dim AdjHoursArray As Range
declares a Range object, which is not an array.

To assign the named range to an array do this:

Dim AdjHoursArray As Variant 'optional, but required if Option Explicit on.
AdjHoursArray = Range("AdjHoursLookup")


AdjHoursArray is now an array of variants (1 to 3, 1 to 4)

--
p45cal


"Bob" wrote:

> I just discovered that by removing ".Value", it fixes the "object required"
> error message problem.
>
> But now I have another issue. Since the size of the named range will vary
> over time, is there a way I can determine the number of non-blank elements in
> the array?
>
> Thanks again for any help.
>
>
> "Bob" wrote:
>
> > I have a named range ("AdjHoursLookup") that currently occupies 12 cells (3
> > rows x 4 columns), but the number of cells will vary over time.
> >
> > Is it possible to assign the named range to a 2-dimensional array? When I
> > excute the following two lines of code, for example, I get an "object
> > required" error message.
> >
> > Dim AdjHoursArray As Range
> > Set AdjHoursArray = Range("AdjHoursLookup").Value
> >
> > Any help would be greatly appreciated. Thanks.
> >

 
Reply With Quote
 
=?Utf-8?B?Qm9i?=
Guest
Posts: n/a
 
      4th Sep 2007
Dave,
Thanks for your help!
Bob


"Dave Peterson" wrote:

> Dim AdjHoursArray As Range
> Set AdjHoursArray = Range("AdjHoursLookup")
> msgbox application.counta(adjhoursarray) & vblf & adjhoursarray.cells.count
>
> =counta() will count all the formulas and constants that are in that
> range--including formulas that evaluate to "" (like =if(a1=5,"ok",""))
>
>
>
> Bob wrote:
> >
> > I just discovered that by removing ".Value", it fixes the "object required"
> > error message problem.
> >
> > But now I have another issue. Since the size of the named range will vary
> > over time, is there a way I can determine the number of non-blank elements in
> > the array?
> >
> > Thanks again for any help.
> >
> > "Bob" wrote:
> >
> > > I have a named range ("AdjHoursLookup") that currently occupies 12 cells (3
> > > rows x 4 columns), but the number of cells will vary over time.
> > >
> > > Is it possible to assign the named range to a 2-dimensional array? When I
> > > excute the following two lines of code, for example, I get an "object
> > > required" error message.
> > >
> > > Dim AdjHoursArray As Range
> > > Set AdjHoursArray = Range("AdjHoursLookup").Value
> > >
> > > Any help would be greatly appreciated. Thanks.
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
=?Utf-8?B?Qm9i?=
Guest
Posts: n/a
 
      4th Sep 2007
Thanks!


"p45cal" wrote:

> Note that te title of this thread seems at odds with the code quoted;
> Dim AdjHoursArray As Range
> declares a Range object, which is not an array.
>
> To assign the named range to an array do this:
>
> Dim AdjHoursArray As Variant 'optional, but required if Option Explicit on.
> AdjHoursArray = Range("AdjHoursLookup")
>
>
> AdjHoursArray is now an array of variants (1 to 3, 1 to 4)
>
> --
> p45cal
>
>
> "Bob" wrote:
>
> > I just discovered that by removing ".Value", it fixes the "object required"
> > error message problem.
> >
> > But now I have another issue. Since the size of the named range will vary
> > over time, is there a way I can determine the number of non-blank elements in
> > the array?
> >
> > Thanks again for any help.
> >
> >
> > "Bob" wrote:
> >
> > > I have a named range ("AdjHoursLookup") that currently occupies 12 cells (3
> > > rows x 4 columns), but the number of cells will vary over time.
> > >
> > > Is it possible to assign the named range to a 2-dimensional array? When I
> > > excute the following two lines of code, for example, I get an "object
> > > required" error message.
> > >
> > > Dim AdjHoursArray As Range
> > > Set AdjHoursArray = Range("AdjHoursLookup").Value
> > >
> > > Any help would be greatly appreciated. Thanks.
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
assigning a multi-dimensional array to a combobox.List??? withoutloops arafael Microsoft Excel Discussion 2 12th Aug 2008 11:36 PM
Out of Memory Error 7 While assigning named range value smartnhandsome Microsoft Excel Programming 8 16th Apr 2008 09:39 PM
Insert into a range from a two dimensional array gimme_this_gimme_that@yahoo.com Microsoft Excel Programming 13 29th May 2007 06:29 AM
Load excel range into multi dimensional array Rishi Dhupar Microsoft Excel Programming 1 26th Jan 2006 03:50 PM
Transferring part of a multi-dimensional array to a range in VBA =?Utf-8?B?Qm9iIEou?= Microsoft Excel Programming 1 27th Jul 2005 03:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:01 PM.