Code verkürzen
15.10.2004 21:40:21
erich
kann mann den folgenden Code verkleinern?
wenn ja bitte um eure Hilfe
P.S. entgültig sind es nämlich 12 optionbutton.
Private Sub Optionbutton1_Click()
Dim iRow As Integer
With Range("A1")
.AutoFilter Field:=1, Criteria1:="=*01*"
End With
iRow = 2
Do Until IsEmpty(Cells(iRow, 2))
If Rows(iRow).Hidden = False Then
ComboBox1.AddItem Cells(iRow, 2).Value
End If
iRow = iRow + 1
Loop
If ComboBox1.ListCount > 0 Then
ComboBox1.ListIndex = 0
End If
End Sub
Private Sub Optionbutton2_Click()
Dim iRow As Integer
With Range("A1")
.AutoFilter Field:=1, Criteria1:="=*02*"
End With
iRow = 2
Do Until IsEmpty(Cells(iRow, 2))
If Rows(iRow).Hidden = False Then
ComboBox1.AddItem Cells(iRow, 2).Value
End If
iRow = iRow + 1
Loop
If ComboBox1.ListCount > 0 Then
ComboBox1.ListIndex = 0
End If
End Sub
Private Sub Optionbutton3_Click()
Dim iRow As Integer
With Range("A1")
.AutoFilter Field:=1, Criteria1:="=*03*"
End With
iRow = 2
Do Until IsEmpty(Cells(iRow, 2))
If Rows(iRow).Hidden = False Then
ComboBox1.AddItem Cells(iRow, 2).Value
End If
iRow = iRow + 1
Loop
If ComboBox1.ListCount > 0 Then
ComboBox1.ListIndex = 0
End If
End Sub
Private Sub Optionbutton4_Click()
Dim iRow As Integer
With Range("A1")
.AutoFilter Field:=1, Criteria1:="=*04*"
End With
iRow = 2
Do Until IsEmpty(Cells(iRow, 2))
If Rows(iRow).Hidden = False Then
ComboBox1.AddItem Cells(iRow, 2).Value
End If
iRow = iRow + 1
Loop
If ComboBox1.ListCount > 0 Then
ComboBox1.ListIndex = 0
End If
End Sub
Private Sub Optionbutton5_Click()
Dim iRow As Integer
With Range("A1")
.AutoFilter Field:=1, Criteria1:="=*05*"
End With
iRow = 2
Do Until IsEmpty(Cells(iRow, 2))
If Rows(iRow).Hidden = False Then
ComboBox1.AddItem Cells(iRow, 2).Value
End If
iRow = iRow + 1
Loop
If ComboBox1.ListCount > 0 Then
ComboBox1.ListIndex = 0
End If
End Sub
gruß
erich