Compile Error When Trying to Pass Date in Range to Custom Object Property

rkaczano

Board Regular
Joined
Jul 24, 2013
Messages
77
I am getting a compile error on the following attempt to pass a date from range in a spreadsheet to a property in a custom class module.

"Definitions of property procedures for the same property are inconsistent....."

I have a custom class called Asset and a custom Collection called Portfolio. In a standard module I add object to the collection in a loop. In that loop I call a FillFromSheet method for a property in the clsAsset class object. This passes my values to the properties.

The FillfromSheet method loads two data values from two ranges in a spreadsheet and passes 2 values to 2 properties in the Asst Class.

The ranges are pulled into the FillfromSheet and resized as only a portion of the range is required. This is passed to the clsAsset properties.

The code stops in the clsAsset class module with the compile error

STANDARD MODULE
'Declare Public Objects
Public asset As clsAsset
Public portfolio As clsPortfolio

Sub CreateObjects()
'*****************
' Objects
Set EventTablerng = Range("XYZ")

Set portfolio = New clsPortfolio
portfolio.FillFromSheet EventTablerng

End Sub

CLASS MODULE(clsPortfolio)
Public Sub FillFromSheet(rng1)
Dim i As Long
Dim obj As clsAsset

'Add objects to collection
For i = 1 To rng1.Rows.Count
'Create new instance of class
Set obj = New clsAsset

With rng1
obj.Month1EventStartDate = rng1.Resize(1, 2).Offset(i, 0)
obj.Month1EventEndDate = rng1.Resize(1, 3).Offset(i, 0)
obj.Month1EventDays = obj.Month1EventEndDate - obj.Month1EventStartDate

End With
'create Object and Loop
Me.Add obj

Next



End Sub

CLASS MODULE(clsAsset)

Private m_sMonth1EventStartDate As Date
Private m_sMonth1EventEndDate As Date
Private m_sMonth1EventDays As Single

Public Property Set Month1EventStartDate(Value As Range)

End Property
Public Property Set Month1EventEndDate(Value As Range)

End Property
Public Property Set Month1EventDays(Value As Single) 'check this
m_sMonth1EventDays
End Property
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,463
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You use Property Set with object types. You should have a Property Let and the code in your property routine currently makes no sense as it is just a variable name.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,567
Messages
5,625,547
Members
416,116
Latest member
Joemamasuka

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
Top