Runtime Error 91 using custom class module

tias

New Member
Joined
Oct 30, 2009
Messages
5
Currently developing my first somewhat tricky spreadsheet application and I'm getting an error 91 which doesn't seem to bear any resemblance to anything google will find.

I'm still pretty new to the whole visual basic thing and find the syntax a little alien (doesn't help if one is used to java)

I define the variable of type declared by class module
I create a new instance and put that in the variable
I attempt to set a property of the instance and get an error.


I have my main subroutine (in a form) that throws the error
Code:
'dim SettingsRef as RefEdit ' from form editor
Option Explicit
Private Sub ApplyButton_Click()
    Dim a As Range
    Set a = Range(SettingsRef) ' This line runs no problem...
    Dim universe As ConwayUniverse
    Set universe = New ConwayUniverse
    ' universe is NOT nothing
    ' Range(...) evaluates without error
    universe.SettingsRef = Range(SettingsRef) 'I get error 91 on this
    Let universe.SettingsRef = Range(SettingsRef) 'I get error 91 on this line too
    'Set universe.SettingsRef = Range(SettingsRef) 'I'd get a compiler error with this
End Sub

And the class module that I'm referring too
Code:
Option Explicit
Private SettingsP As Range ' top left cell of settings block
Public Property Get SettingsRef() As Range
    SettingsRef = Settings(0, 0)
End Property
Public Property Get Settings(row As Integer, col As Integer) As Range
    Settings = SettingsP.Offset(row, col)
End Property
Public Property Let SettingsRef(val As Range)
    SettingsP = val
End Property
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Set needs to be used with Ranges.

Code:
Private SettingsP As Range ' top left cell of settings block

Public Property Get SettingsRef() As Range
    [COLOR="red"]Set[/COLOR] SettingsRef = Settings(0, 0)
End Property

Public Property Get Settings(row As Integer, col As Integer) As Range
    [COLOR="Red"]Set[/COLOR] Settings = SettingsP.Offset(row, col)
End Property

Public Property [I][COLOR="Red"]Set[/COLOR][/I] SettingsRef(val As Range)
    [COLOR="red"]Set[/COLOR] SettingsP = val
End Property

I'd also avoid nameing a RefEdit control the same name as a Property of a custom class. I'm not sure if this will compile, but even if it did, I'd find it confusing.
Rich (BB code):
Set universe.SettingsRef = Range(SettingsRef)
 
Last edited:
Upvote 0
Thanks a million for the quick response
the thing with set still confuses me a lot, but got the code working now
 
Upvote 0

Forum statistics

Threads
1,215,201
Messages
6,123,617
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top