I have a roughly formatted dataset to work with, and I'm using multiple Find
methods to grab the datapoints I need. My sample database has three periods of data (all on one sheet), with multiple officer names. A name may or may not be in a particular period. I am using the variable officerSearch
to store the address which serves as the anchor point for the following Find
method. This works unless an officer name is not in a particular period, then my Find
methods get off course. More detail in my code comments.
For Each k In dateArray.keys 'loops through my periods. Each key is a unique date
For i = 0 To officerListBox.ListCount - 1
If officerListBox.Selected(i) = True Then 'Performs _
Find methods for each officer selected in list box
officerSearch = Cells.Find(what:=CDate(k), LookIn:=xlFormulas, _
searchorder:=xlByRows, searchdirection:=xlNext).Address 'Finds first instance of the first period (k)
officerSearch = Cells.Find(what:=officerListBox.List(i), _
after:=Range(officerSearch), LookIn:=xlValues, lookat:=xlWhole, _
searchorder:=xlByRows, searchdirection:=xlNext).Address _
'Finds officer name starting after the date cell was found. _
But if the raw data set doesn't have the officer name in that period, _
my Find method will find an officer name further on down the sheet _
(or loop around at the beginning of the sheet) where the name is found in a different period.
officerSearch = Cells.Find(what:="Gross Loans", after:=Range(officerSearch), _
LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, _
searchdirection:=xlNext).Address 'Finds the cell labeled Gross Loans starting after an officer name is found
officerSearch = Cells.Find(what:="Total 30 - 59 days past due", _
after:=Range(officerSearch), LookIn:=xlValues, lookat:=xlWhole, _
searchorder:=xlByRows, searchdirection:=xlNext).Address 'Finds the cell _
labeled Total 30-59 days past due starting after _
an officer name is found.
End If
Next i 'Starts the find loop over for the next selected officer name
Next k 'Starts the find loop over for the next period in the dataset
So my 1st, 3rd, and 4th Find methods are guaranteed to be present in the spot I expect, but the 2nd Find method may not be located in the period my loop is searching for, therefore throwing everything else off. I'm stumped on how to account for this.