can I set my own object type like in java

ribbs2521

Board Regular
Joined
Sep 8, 2007
Messages
158
I was wondering if there is a way, in VBA to create my own object type. I know in java I would have a class with a constructor to generate the object. Basically what I'm doing is I have a list of products, each product has a yield, repeat repair, Turn Around Time, Backlog and output. Rather than creating arrays for each I want to create objects of type "product" so I could do something like this:

product1.yield = 42.5
product1.backlog = 102
product2.yield = 50.4
.....
......

this way, if I have to add a product later it will be much easier than having to adjust the arrays.
So, if there is a way to do that in Excel, how would I do it?
 

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.
You can define your own data type like this

Code:
Type salesResults
    spring  As Single
    summer  As Single
    autumn  As Single
    winter  As Single
End Type

You can then define a variable as that data type

Code:
Dim MyStore As salesResults

and assign values to it like

Code:
With MyStore
    .spring = 1000
    .summer = 250
    .autumn = 700
    .winter = 200
End With
 
Upvote 0
actually, one more thing, is there any way to initiate these as 0 by default. It appears that, like normal variables, these static variables are not initiated as 0 or "". I get an error saying that productx.output = empty since that product wasn't in the pivot table I'm looking at.
 
Upvote 0
actually, one more thing, is there any way to initiate these as 0 by default. It appears that, like normal variables, these static variables are not initiated as 0 or "". I get an error saying that productx.output = empty since that product wasn't in the pivot table I'm looking at.

I think that they should be 0 or "" or Nothing by default. Perhaps you need to post your code.
 
Upvote 0
That's odd, since you said that, I tried it again and it works fine. I even ran it a few more times and it works fine still. Must have been I fluke I guess. Thanks again for your help.
 
Upvote 0

Forum statistics

Threads
1,214,800
Messages
6,121,641
Members
449,044
Latest member
hherna01

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