ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Function returns Range -- error 91 (https://www.excelbanter.com/excel-programming/319057-function-returns-range-error-91-a.html)

[email protected]

Function returns Range -- error 91
 
This function...

Function Range4(R1 As Integer, C1 As Integer, R2 As Integer, C2 As
Integer) As Range
Set Range4 = Range(Cells(R1, C1), Cells(R2, C2))
End Function

.... works fine through the assignment to Range4 (gets the correct
range), but hangs at the End Funciton line with

Run-time error '91':
Object variable or With block variable not set


What am I doing wrong?

I've tried: adding "ActiveSheet." to everything; an auxilliary Range
variable; searching this group.

Thanks. --David.

PS: Anybody know a better way to construct a simple rectangular range
using numeric arguments rather than string addresses. But I'd still
like to know why this function fails. It fails even if I assign a very
simple range to Range4, like ActiveCell.


Bob Phillips[_6_]

Function returns Range -- error 91
 
When I called it using

Set r = Range4(1, 2, 3, 4)

it worked fine. What values are you passing?

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
oups.com...
This function...

Function Range4(R1 As Integer, C1 As Integer, R2 As Integer, C2 As
Integer) As Range
Set Range4 = Range(Cells(R1, C1), Cells(R2, C2))
End Function

... works fine through the assignment to Range4 (gets the correct
range), but hangs at the End Funciton line with

Run-time error '91':
Object variable or With block variable not set


What am I doing wrong?

I've tried: adding "ActiveSheet." to everything; an auxilliary Range
variable; searching this group.

Thanks. --David.

PS: Anybody know a better way to construct a simple rectangular range
using numeric arguments rather than string addresses. But I'd still
like to know why this function fails. It fails even if I assign a very
simple range to Range4, like ActiveCell.




Tom Ogilvy

Function returns Range -- error 91
 
In a general module, this worked fine for me:

Function Range4(R1 As Integer, C1 As Integer, R2 As Integer, C2 As Integer)
As Range
Set Range4 = Range(Cells(R1, C1), Cells(R2, C2))
End Function

Sub Tester3()
Dim i1 As Integer, i2 As Integer
Dim j1 As Integer, j2 As Integer
i1 = 10
i2 = 20
j1 = 5
j2 = 26
MsgBox Range4(i1, j1, i2, j2).Address
End Sub

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
This function...

Function Range4(R1 As Integer, C1 As Integer, R2 As Integer, C2 As
Integer) As Range
Set Range4 = Range(Cells(R1, C1), Cells(R2, C2))
End Function

... works fine through the assignment to Range4 (gets the correct
range), but hangs at the End Funciton line with

Run-time error '91':
Object variable or With block variable not set


What am I doing wrong?

I've tried: adding "ActiveSheet." to everything; an auxilliary Range
variable; searching this group.

Thanks. --David.

PS: Anybody know a better way to construct a simple rectangular range
using numeric arguments rather than string addresses. But I'd still
like to know why this function fails. It fails even if I assign a very
simple range to Range4, like ActiveCell.




David Lewis[_2_]

Function returns Range -- error 91
 
Hmmm... Well, I tried this on an entirely blank workbook, immediately
aftr rebooting my system...

Function Range4(R1 As Integer, C1 As Integer, R2 As Integer, C2 As
Integer) As Range
Set Range4 = ActiveCell
End Function

Sub SetupStuff()
Dim R As Range
R = Range4(1, 2, 3, 5)
End Sub

.... and it still fails the same way. Obviously something is broken.
Good news -- I can still program VBA. Bad news -- I'm stuck, and
wondering what else what might go wrong?

Any ideas? I'm using: VB 6.3; Excel 2002 SP3; WinXP Pro SP1; on a Dell
Latitude.


Chip Pearson

Function returns Range -- error 91
 
In your test code, you need to change
R = Range4(1, 2, 3, 5)
to
Set R = Range4(1, 2, 3, 5)



"David Lewis" wrote in message
oups.com...
Hmmm... Well, I tried this on an entirely blank workbook,
immediately
aftr rebooting my system...

Function Range4(R1 As Integer, C1 As Integer, R2 As Integer, C2
As
Integer) As Range
Set Range4 = ActiveCell
End Function

Sub SetupStuff()
Dim R As Range
R = Range4(1, 2, 3, 5)
End Sub

... and it still fails the same way. Obviously something is
broken.
Good news -- I can still program VBA. Bad news -- I'm stuck,
and
wondering what else what might go wrong?

Any ideas? I'm using: VB 6.3; Excel 2002 SP3; WinXP Pro SP1; on
a Dell
Latitude.




David Lewis[_2_]

Function returns Range -- error 91
 
Duh. Thanks!

--David.


David Lewis[_2_]

Function returns Range -- error 91
 
Duh!

Thanks!!!



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

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