Object property taken from worksheet cell?

nigelandrewfoster

Well-known Member
Joined
May 27, 2009
Messages
747
Hello, feeling my way forward in object oriented approach to structuring my code. Quick question. In the example I'm working on I have a class called clsTeam. I give the team a name using oTeam.Name="Team 1", for example:

Code:
Option Explicit

Private pName As String


Public Property Get Name() As String
    Name = pName
End Property


Public Property Let Name(Value As String)
    pName = Value
End Property

How can I modify the code so that it always takes the value from a table of names in the worksheet please (i.e. is always linked to the cell object)? What I want to be able to achieve is to be able to use Teams(1).Name to retrieve the cell contents of cell A2 in a worksheet, Teams(2).Name to retrieve the name in A3, etc. Once I have learned to do this, I can then utilise Teams(1).Colour to retrieve the .Interior.Color property of that cell directly. Is this possible? The only way forward I could think of was by retrieving the index of the Team object from the Teams collection and using that as an offset, but couldn't get any further.

Thanks for your time.
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
That doesn't seem like great design to me, but if you want the Team to be linked directly to a specific cell, you could assign the cell directly as a property of the class so that your other properties can simply read that cell directly.
 
Upvote 0
Thanks. I will try. The team names and colours are the only things the user is to provide. Given the fact objects cease to be when macros finish running I need a way of storing their values. The rest can be rebuilt each time the macro runs. I'm really using this as an exercise in understanding objects with a view to eventually moving towards other languages.
 
Upvote 0
If you have a collection of the objects, accessing one object via its index automatically gives you an object reference and thus access to all its properties, so I don't really understand the question, I'm afraid.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

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