2011-10-24 70 views
0

我收到这个错误,我不知道原因。 我有以下的代码:无法设置List属性。无效的财产值

Private Sub repereche_Change() 
Dim ws As Worksheet 
Set ws = Worksheets("BD_IR") 
Dim Rand As Long, Rand2 As Long 
Dim prestrangere As Long 
Dim prestrangere2 As Long 
Dim bila As Long 
Dim ws2 As Worksheet 
Set ws2 = Worksheets("BD_AR") 
prestrangere = 0 
prestrangere2 = 0 
bila = 10 
Rand = 3 
Rand2 = 3 

Do While ws.Cells(Rand, 3).Value <> "" And Rand < 65000 
    If Me.repereche.Value = Mid(ws.Cells(Rand, 3), 4, 10) Then 
     Do While ws2.Cells(Rand2, 3).Value <> "" And Rand2 < 65000 
      If Me.repereche.Value = Mid(ws2.Cells(Rand2, 3), 4, 10) Then 
       If ws.Cells(Rand, 7) <> "" Then 
       prestrangere = (((ws2.Cells(Rand2, 7) - 400) * 10) - ((ws.Cells(Rand, 6) - 400) * 10) - (bila * 1.414 * 2)) - 10 
       prestrangere2 = (((ws2.Cells(Rand2, 6) - 400) * 10) - ((ws.Cells(Rand, 7) - 400) * 10) - (bila * 1.414 * 2)) - 10 
       Else 
       prestrangere = (((ws2.Cells(Rand2, 6) - 400) * 10) - ((ws.Cells(Rand, 6) - 400) * 10) - (bila * 1.414 * 2)) - 10 
       End If 
       gksluri.AddItem ws.Cells(Rand, 4).Value 'comanda IR 
       gksluri.List(gksluri.ListCount - 1, 1) = ws.Cells(Rand, 5) 'inel IR 
       gksluri.List(gksluri.ListCount - 1, 2) = ws.Cells(Rand, 6) 'GKSL IR 
       gksluri.List(gksluri.ListCount - 1, 3) = ws.Cells(Rand, 7) 'GKSL 2 IR 
       gksluri.List(gksluri.ListCount - 1, 4) = ws2.Cells(Rand2, 4) 'comanda AR 
       gksluri.List(gksluri.ListCount - 1, 5) = ws2.Cells(Rand2, 5) 'inel AR 
       gksluri.List(gksluri.ListCount - 1, 6) = ws2.Cells(Rand2, 6) 'GKSL AR 
       gksluri.List(gksluri.ListCount - 1, 7) = ws2.Cells(Rand2, 7) 'GKSL 2 AR 
       gksluri.List(gksluri.ListCount - 1, 8) = bila 
       gksluri.List(gksluri.ListCount - 1, 9) = prestrangere 
       gksluri.List(gksluri.ListCount - 1, 10) = "test" 'HERE IS THE ERROR 
      End If 
     Rand2 = Rand2 + 1 
     Loop 
    End If 
Rand2 = 3 
Rand = Rand + 1 
Loop 
End Sub 

gksluri是一个列表框。列表框在ColumnCount属性中设置了11个列。如果我删除线

gksluri.List(gksluri.ListCount - 1, 10) = "test" 

它工作正常。我究竟做错了什么?问题在哪里?我找不到任何东西。 非常感谢!

+1

'.List'是0基于阵列,所以重新编号0..9而非1..10 –

+0

它编号0-10未0-9但对于第一项我用列表框.Value而不是.List –

+0

类似这样的东西 –

回答