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

rkaczano

Board Regular
Joined
Jul 24, 2013
Messages
141
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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