![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 02:50 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com