Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Function returns Range -- error 91

Duh. Thanks!

--David.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Function returns Range -- error 91

Duh!

Thanks!!!

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
IF(AND(OR function returns #VALUE! error Linda Excel Worksheet Functions 3 April 15th 09 06:00 PM
LINEST() function returns error. Albert[_2_] Excel Discussion (Misc queries) 1 October 28th 07 07:53 PM
Find function returns the #VALUE! error value Ken Excel Discussion (Misc queries) 2 October 29th 06 01:59 AM
AVERAGE function returns #DIV/0! error KhaVu Excel Discussion (Misc queries) 7 January 9th 06 07:06 PM
Named range returns 1004 error Stu D. Excel Programming 0 September 3rd 04 09:37 AM


All times are GMT +1. The time now is 05:12 PM.

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

About Us

"It's about Microsoft Excel"