I've been learning how to use classes in VBA over the past couple of months but am having a problem figuring out what's the proper way of grouping multiple class items together so I can iterate through them.
For example, I have a class named clsPersons with Properties such as Name, Gender, DOB, and Age (Today - DOB). If I just wanted to add one person I would do the following:
Dim Person As New clsPersons
Person.Name = "Phillip"
Person.Gener = "Male"
Person.DOB = "#1/1/2000"
' Person.Age would be automatically set by adding Person.DOB
However, if I had a spreadsheet with everyone on it and decide to create a report with everyone who's name begins with the letter "P", then I first need some kind of object to use (collection, dictionary, etc) and something like this to fill it:
Dim Person As New clsPersons
Dim lastRow As Long
lastRow = Sheet1.Cells(Rows.Count, 1).Row(xlUp).End
For i = 1 To lastRow
If Worksheet.Function.Left(Sheet1.Cells(i, 1), 1) = "P" Then
Person.Name = Sheet1.Cells(i, 1)
Person.Gener = Sheet1.Cells(i, 2)
Person.DOB = Sheet1.Cells(i, 3)
End If
Next i
After filling it I would then want to be able to loop through it to pull items out, so something like this:
For Each Person In objPeople
Sheet2.Cells(i, 1) = Person.Name
Sheet2.Cells(i, 1) = Person.Gender
Sheet2.Cells(i, 1) = Person.Age
Next Person
Hopefully what I've outlined makes sense. Simply put I'm just looking for the proper way to group the People together into one object that I can iterate through later on in my procedure.