Collections and Classes

jadox

New Member
Joined
Feb 16, 2014
Messages
38
Hi,

Can anyone help me with this?

I have a class, lets say with Name, Address and Salary properties. And a Collection (Employees) with all the classes.

Is there a way to search for the maxvalue of the Salary, from all the classes in the collection?

Thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try something like this...

<font face=Calibri>    <SPAN style="color:#00007F">Dim</SPAN> Employees       <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">New</SPAN> Collection<br>    <SPAN style="color:#00007F">Dim</SPAN> cEmp            <SPAN style="color:#00007F">As</SPAN> clsEmp<br>    <SPAN style="color:#00007F">Dim</SPAN> sEmployee       <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> MaxSalary       <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br>    <br>    <SPAN style="color:#007F00">'Your code to store class objects in your collection</SPAN><br>    <br>    MaxSalary = 0<br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cEmp <SPAN style="color:#00007F">In</SPAN> Employees<br>        <SPAN style="color:#00007F">If</SPAN> cEmp.Salary > MaxSalary <SPAN style="color:#00007F">Then</SPAN><br>            MaxSalary = cEmp.Salary<br>            sEmployee = cEmp.Name<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">Next</SPAN> cEmp<br>    <br>    MsgBox "Employee:  " & sEmployee & "; Salary:  " & MaxSalary<br>    </FONT>

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,176
Members
448,554
Latest member
Gleisner2

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