View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
[email protected][_2_] gimme_this_gimme_that@yahoo.com[_2_] is offline
external usenet poster
 
Posts: 236
Default Why does my code randomly ignore variable initialisation?

It looks to me like the problem has to do with vestige values of
cmbGCodes.
Setting the ListIndex to zero doesn't clear stale values. Each time
PopulatecmbGrades executes all you're doing is adding new values to
the end of cmbGCodes.

Try recreating a brand new cmbGCodes in PopulatecmbGrades() or each
time just before PopulatecmbGrades() gets called.




On Jul 31, 3:20 am, Graham Y
wrote:
Can anyone tell me why sometimes this code should fail on line 5 with y=0 ...
1 Private Sub PopulatecmbGrades()
2 Dim y As Single
3 With Sheets("Sheet5")
4 For y = 3 To .[H3].CurrentRegion.Rows.count
5 cmbGCodes.AddItem .Cells(y, 8)
6 cmbGrades.AddItem .Cells(y, 9)
7 Next
8 End With
9 cmbGCodes.ListIndex = 0
10 cmbGrades.ListIndex = 0
11 End Sub

.[H3].CurrentRegion.Rows.count = 13 currently

I do use y elsewhere and it may be 0 but a) it would be out of scope here
and b) it should be set by the For loop.