在For循环中select大小写溢出错误

我是一名相对较小的VBA知识的CAD工程师,但今天我决定修改一个5年的程序,并遇到这个问题:

我有一个combobox,可以显示来自2个不同的工作表的项目,这取决于select两个电台中的哪一个。 这适用于案例。 老实说,我不知道案件是如何运作的,所以我不知道组合箱怎样知道要采取哪种情况,但是它起作用了,所以我没有改变它。

现在,代码是这样的:

这意味着如果我添加一个新的行到表中,我不得不复制这些案件select的东西

Private Sub ComboBox5_Change() 'Auswahl Rohr Select Case ComboBox5.Value Case Tabelle6.Cells(4, 3) 'Welle in Rohr LängRo = Tabelle6.Cells(4, 6) OnCenRo = Tabelle6.Cells(4, 7) OffCeRo = Tabelle6.Cells(4, 8) MinRRo = Tabelle6.Cells(4, 9) Case Tabelle13.Cells(4, 3) 'ROHR IN ROHR LängRo = Tabelle13.Cells(4, 6) OnCenRo = Tabelle13.Cells(4, 7) OffCeRo = Tabelle13.Cells(4, 8) MinRRo = Tabelle13.Cells(4, 9) Case Tabelle13.Cells(5, 3) 'ROHR IN ROHR LängRo = Tabelle13.Cells(5, 6) OnCenRo = Tabelle13.Cells(5, 7) OffCeRo = Tabelle13.Cells(5, 8) MinRRo = Tabelle13.Cells(5, 9) End Select End Sub 

我试图解决这个像这样的东西:

 Private Sub ComboBox5_Change() 'Auswahl Rohr Dim for1 As Long Dim for2 As Long For for2 = 3 To 7 If Tabelle6.Cells(for2, 3) = "" Then GoTo fert Else Select Case ComboBox5.Value Case Tabelle6.Cells(for2, 3) 'Welle in Rohr LängRo = Tabelle6.Cells(for2, 6) OnCenRo = Tabelle6.Cells(for2, 7) OffCeRo = Tabelle6.Cells(for2, 8) MinRRo = Tabelle6.Cells(for2, 9) End Select End If Next For for1 = 3 To 7 If Tabelle10.Cells(for1, 3) = "" Then GoTo fert Else Select Case ComboBox5.Value Case Tabelle10.Cells(for1, 3) 'ROHR IN ROHR LängWe = Tabelle10.Cells(for1, 6) OnCenWe = Tabelle10.Cells(for1, 7) OffCeWe = Tabelle10.Cells(for1, 8) MinRWe = Tabelle10.Cells(for1, 9) End Select End If Next fert: End Sub 

但是现在当我按下一个使用LängRO的button时,我得到一个溢出错误,我不知道为什么

未经testing:

 Private Sub ComboBox5_Change() 'Auswahl Rohr Dim v, arrRows, c v = ComboBox5.Value arrRows = Array(Tabelle6.Cells(4, 3), _ Tabelle13.Cells(4, 3), _ Tabelle13.Cells(5, 3)) For Each c In arrRows If c.Value = v Then 'Found a match - assign from that row... With c.EntireRow LängRo = .Cells(6) OnCenRo = .Cells(7) OffCeRo = .Cells(8) MinRRo = .Cells(9) End With Exit For 'stop looping End If Next c End Sub 

我不确定我是否遵循了你的布局,但是…