Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default problem:Structure with Object reference (TYPE...END TYPE)

I keep getting the dreaded "Runtime Error '91'....
Object Variable or With-block variable not set"

Type RangeTestType
TestCount As Long ' Cell Count
TestRange As Object ' Range RefString variable stores a name.
End Type
Dim retval as RangeTestType
Dim dataRange As Range
Dim lCellcnt As Long
Dim x as Object

Set dataRange = Range("A1:" & "C" & ActiveSheet.Rows.Count)
x = dataRange
lCellcnt = dataRange.Cells.Count
retval.TestCount = lCellcnt
retval.TestRange = x <= THIS STATEMENT TRIGGERS ERROR

When I replace the Object with "Range", I get the exact same error.
Somehow, passing objects within a structure appear to be
problematic....
any help greatly appreciated. (Excel 2003)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default problem:Structure with Object reference (TYPE...END TYPE)

You must "Set" objects.

Type RangeTestType
TestCount As Long ' Cell Count
TestRange As Object ' Range RefString variable stores a name.
End Type


Sub a()
Dim retval As RangeTestType
Dim dataRange As Range
Dim lCellcnt As Long
Dim x As Object

Set dataRange = Range("A1:" & "C" & ActiveSheet.Rows.Count)
Set x = dataRange
lCellcnt = dataRange.Cells.Count
retval.TestCount = lCellcnt
Set retval.TestRange = x
End Sub


--
Jim
"syswizard" wrote in message
ups.com...
|I keep getting the dreaded "Runtime Error '91'....
| Object Variable or With-block variable not set"
|
| Type RangeTestType
| TestCount As Long ' Cell Count
| TestRange As Object ' Range RefString variable stores a name.
| End Type
| Dim retval as RangeTestType
| Dim dataRange As Range
| Dim lCellcnt As Long
| Dim x as Object
|
| Set dataRange = Range("A1:" & "C" & ActiveSheet.Rows.Count)
| x = dataRange
| lCellcnt = dataRange.Cells.Count
| retval.TestCount = lCellcnt
| retval.TestRange = x <= THIS STATEMENT TRIGGERS ERROR
|
| When I replace the Object with "Range", I get the exact same error.
| Somehow, passing objects within a structure appear to be
| problematic....
| any help greatly appreciated. (Excel 2003)
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default problem:Structure with Object reference (TYPE...END TYPE)

Type RangeTestType
TestCount As Long ' Cell Count
TestRange As Object ' Range RefString variable stores a name.
End Type

Sub ABC()
Dim retval As RangeTestType
Dim dataRange As Range
Dim lCellcnt As Long


Set dataRange = Range("A1:" & "C" & ActiveSheet.Rows.Count)
lCellcnt = dataRange.Cells.Count
retval.TestCount = lCellcnt
Set retval.TestRange = dataRange
MsgBox retval.TestCount & " address: " & retval.TestRange.Address
End Sub

worked fine for me.

--
Regards,
Tom Ogilvy





"syswizard" wrote in message
ups.com...
I keep getting the dreaded "Runtime Error '91'....
Object Variable or With-block variable not set"

Type RangeTestType
TestCount As Long ' Cell Count
TestRange As Object ' Range RefString variable stores a name.
End Type
Dim retval as RangeTestType
Dim dataRange As Range
Dim lCellcnt As Long
Dim x as Object

Set dataRange = Range("A1:" & "C" & ActiveSheet.Rows.Count)
x = dataRange
lCellcnt = dataRange.Cells.Count
retval.TestCount = lCellcnt
retval.TestRange = x <= THIS STATEMENT TRIGGERS ERROR

When I replace the Object with "Range", I get the exact same error.
Somehow, passing objects within a structure appear to be
problematic....
any help greatly appreciated. (Excel 2003)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default problem:Structure with Object reference (TYPE...END TYPE)

Try: Set retval.TestRange = x

Hth,
Merjet


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default problem:Structure with Object reference (TYPE...END TYPE)

Hi, I think you should move the set statement on retval before
"retval.TestCount = lCellcnt" statement.

"Jim Rech" wrote:

You must "Set" objects.

Type RangeTestType
TestCount As Long ' Cell Count
TestRange As Object ' Range RefString variable stores a name.
End Type


Sub a()
Dim retval As RangeTestType
Dim dataRange As Range
Dim lCellcnt As Long
Dim x As Object

Set dataRange = Range("A1:" & "C" & ActiveSheet.Rows.Count)
Set x = dataRange
lCellcnt = dataRange.Cells.Count
retval.TestCount = lCellcnt
Set retval.TestRange = x
End Sub


--
Jim
"syswizard" wrote in message
ups.com...
|I keep getting the dreaded "Runtime Error '91'....
| Object Variable or With-block variable not set"
|
| Type RangeTestType
| TestCount As Long ' Cell Count
| TestRange As Object ' Range RefString variable stores a name.
| End Type
| Dim retval as RangeTestType
| Dim dataRange As Range
| Dim lCellcnt As Long
| Dim x as Object
|
| Set dataRange = Range("A1:" & "C" & ActiveSheet.Rows.Count)
| x = dataRange
| lCellcnt = dataRange.Cells.Count
| retval.TestCount = lCellcnt
| retval.TestRange = x <= THIS STATEMENT TRIGGERS ERROR
|
| When I replace the Object with "Range", I get the exact same error.
| Somehow, passing objects within a structure appear to be
| problematic....
| any help greatly appreciated. (Excel 2003)
|





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default problem:Structure with Object reference (TYPE...END TYPE)

Thanks guys for the help...just when I thought I was getting good at
this.....NOT !!
Strangely, I scoured the entire net look for someone who had used an
object within a TYPE using Excel. None, nada, zip to be found.

As an interesting aside, when you have an object within a TYPE
structure,
you cannot reference it directly from the structure. It must be "set"
first.
Assuming TD is the structure reference.

Dim xRange As Range
Set xRange = TD.TestRange
dTotal = dTotal + TD.TestRange.Cells.Offset(ix).Value <= Fails !!!
dTotal = dTotal + xRange.Cells.Offset(ix).Value <= Works Fine !!!

I wonder if that would not be the case had I used a RANGE in the
structure instead of OBJECT ?


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default problem:Structure with Object reference (TYPE...END TYPE)

All objects of any type (including Range) need to be set first. (as I showed
you in my code).

--
Regards,
Tom Ogilvy


"syswizard" wrote:

Thanks guys for the help...just when I thought I was getting good at
this.....NOT !!
Strangely, I scoured the entire net look for someone who had used an
object within a TYPE using Excel. None, nada, zip to be found.

As an interesting aside, when you have an object within a TYPE
structure,
you cannot reference it directly from the structure. It must be "set"
first.
Assuming TD is the structure reference.

Dim xRange As Range
Set xRange = TD.TestRange
dTotal = dTotal + TD.TestRange.Cells.Offset(ix).Value <= Fails !!!
dTotal = dTotal + xRange.Cells.Offset(ix).Value <= Works Fine !!!

I wonder if that would not be the case had I used a RANGE in the
structure instead of OBJECT ?



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
object on RHS when there is a type-mismatch [email protected] Excel Programming 0 October 12th 06 02:00 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
On-the-fly determination of object type? Ed Excel Programming 2 May 17th 05 08:37 PM
automation object type library reference Kevan Hanson Excel Programming 2 August 4th 04 02:29 AM
User Defined Type Structure - want it to be variable not numeric literal WyoCracker Excel Programming 1 July 21st 03 09:28 PM


All times are GMT +1. The time now is 12:17 AM.

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"