Cells(Rows.Count, 1).End(xlUp).row
For row = 2 To numrows
Set m_oStep = New cStep
For col = 1 To m_iNumSettings
Select Case col
Case 1
m_oStep.Order = m_oWorksheet.Cells(row, col).Value
sKey = CStr(m_oStep.Order)
Case 2
m_oStep.Page = m_oWorksheet.Cells(row, col).Value
CHAPTER 4 n USERFORMS 175
Case 3
m_oStep.Caption = m_oWorksheet.Cells(row, col).Value
End Select
Next col
colReturn.Add m_oStep, sKey
Next row
m_iNumSteps = colReturn.Count
Set PageSettings = colReturn
End Property
The first thing we??™re doing is getting the number of rows in the used area on the worksheet:
numrows = m_oWorksheet.Cells(Rows.Count, 1).End(xlUp).Row
nNote Although Excel??™s Worksheet object has a Rows.Count method, we cannot use that here
(m_oWorksheet.Rows.Count). That would return the total number of rows in the worksheet, which would
not only give us an incorrect value, but would also overflow our Integer variable.
Next we??™re using the number-of-used-rows value just returned in a loop that will populate
the collection of cStep objects. Let??™s look at that code:
For row = 2 To numrows
Set m_oStep = New cStep
For col = 1 To m_iNumSettings
Select Case col
Case 1
m_oStep.Order = m_oWorksheet.Cells(row, col).Value
sKey = CStr(m_oStep.Order)
Case 2
m_oStep.Page = m_oWorksheet.Cells(row, col).Value
Case 3
m_oStep.Caption = m_oWorksheet.Cells(row, col).Value
End Select
Next col
colReturn.Add m_oStep, sKey
Next row
The first thing we do is instantiate a new cStep object.
Pages:
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185