Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default returning data of type range; error 91

A subroutine calls a function which is supposed to return data of type
"range". The
function fails with error 91. I suspect I am not differentiating a
"reference" to data from actual data. Here is the code:

Sub A()
Dim b as Range
Dim i as long
set b = BRange()
i = b.Columns.Count
end Sub

Function BRange() as Range
Dim aRange as Range
Dim i as long

set aRange = Application.InputBox(prompt:="select table",Type:=8)
i = aRange.columns.count
BRange = aRange
end Function

NOTES: Code fails when I attempt to assign aRange to BRange. I get a
run-time error of '91' - "object variable or with block variable not set".
I should point out that the Application.InputBox DOES return the range as I
CAN read at least one value through the variable, i, within the
function,BRange. (i can read the rest but kept this example simple by
omitting them)

please help me understand what I am doing wrong. I seem to be ignorant
about something and hence can't overcome this error
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default returning data of type range; error 91

You'll probably say DOH when you read this.

You have
BRange = aRange

You need
Set BRange = aRange

HTH,
Barb Reinhardt


"whburling" wrote:

A subroutine calls a function which is supposed to return data of type
"range". The
function fails with error 91. I suspect I am not differentiating a
"reference" to data from actual data. Here is the code:

Sub A()
Dim b as Range
Dim i as long
set b = BRange()
i = b.Columns.Count
end Sub

Function BRange() as Range
Dim aRange as Range
Dim i as long

set aRange = Application.InputBox(prompt:="select table",Type:=8)
i = aRange.columns.count
BRange = aRange
end Function

NOTES: Code fails when I attempt to assign aRange to BRange. I get a
run-time error of '91' - "object variable or with block variable not set".
I should point out that the Application.InputBox DOES return the range as I
CAN read at least one value through the variable, i, within the
function,BRange. (i can read the rest but kept this example simple by
omitting them)

please help me understand what I am doing wrong. I seem to be ignorant
about something and hence can't overcome this error

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default returning data of type range; error 91


First, thank you for responding so quickly. Very grateful. You may have
thought that I would have said, "doh" but i think I failed to grasp what a
reference was and what references required.

let me offer several examples and give you my understandings about this
subject matter and if i am wrong, please correct me.

if i have
variable = 6
my understanding is that the number 6 is equated directly with
Variable. wherever variable is used, 6 has been substituted for the variable.

if i have variable = cell(i,j) where different cells may be selected,
I am not sure what the variable is. I know the association can not be
directly made as the compiler has long since done its thing

on the other hand
set variable = 6
my understanding is that through the key term, "set", the variable is
associated with an address pointing to where the 6 is stored. This permits
the variable to have changing values.

the wierd thing is that I think I see the above all the time (variable =
cell(i,j) )
where no "set" is used.

i think i am confused. please help me out.
Thank you
Bil


do i need to do anything special with referenced data other than use the term
set to define the variable as a reference (pointer?)

"Barb Reinhardt" wrote:

You'll probably say DOH when you read this.

You have
BRange = aRange

You need
Set BRange = aRange

HTH,
Barb Reinhardt


"whburling" wrote:

A subroutine calls a function which is supposed to return data of type
"range". The
function fails with error 91. I suspect I am not differentiating a
"reference" to data from actual data. Here is the code:

Sub A()
Dim b as Range
Dim i as long
set b = BRange()
i = b.Columns.Count
end Sub

Function BRange() as Range
Dim aRange as Range
Dim i as long

set aRange = Application.InputBox(prompt:="select table",Type:=8)
i = aRange.columns.count
BRange = aRange
end Function

NOTES: Code fails when I attempt to assign aRange to BRange. I get a
run-time error of '91' - "object variable or with block variable not set".
I should point out that the Application.InputBox DOES return the range as I
CAN read at least one value through the variable, i, within the
function,BRange. (i can read the rest but kept this example simple by
omitting them)

please help me understand what I am doing wrong. I seem to be ignorant
about something and hence can't overcome this error

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
Type Mismatch error while checking range value illini_99[_2_] Excel Programming 3 August 21st 08 06:36 PM
Returning data from within a date range Cdn Gas Guy Excel Programming 10 January 16th 08 12:06 AM
Returning value from a range of data tinagi Excel Discussion (Misc queries) 1 February 20th 06 03:05 AM
Strange data type error johnsday Excel Programming 7 January 20th 06 04:08 PM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM


All times are GMT +1. The time now is 03:32 PM.

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"