Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
500to504
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
500to504
500to504
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Code verkürzen

Code verkürzen
15.10.2004 21:40:21
erich
Hallo Excelprofis,
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

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Code verkürzen
Bert

Private Sub Optionbutton1_Click()
call eine_fuer_alle("=*01*")
End Sub


Private Sub Optionbutton2_Click()
call eine_fuer_alle("=*02*")
End Sub

usw. für alle Optionbutton
Sub eine_fuer_alle(crit as string)
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
Anzeige
So natürlich, vergiss die erste Antwort
Bert

Private Sub Optionbutton1_Click()
call eine_fuer_alle("=*01*")
End Sub


Private Sub Optionbutton2_Click()
call eine_fuer_alle("=*02*")
End Sub

usw. für alle Optionbutton
Sub eine_fuer_alle(crit as string)
Dim iRow As Integer
With Range("A1")
.AutoFilter Field:=1, Criteria1:=crit
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
Anzeige
Danke Bert
Erich
Hallo Bert,
Danke für deine Hilfe es funktioniert super, danke
gruß
erich
AW: Code verkürzen
Reinhard
Hi Erich,
oder mit Optionsfekdern aus "Formular", Code in ein Modul und allen zuweisen.
Gruß
Reinhard
Sub eine_fuer_alle()
AC = Right(Application.Caller, 2)
If Left(AC, 1) > "9" Or Left(AC, 1) < "1" Then AC = "0" & Right(AC, 1)
Dim iRow As Integer
With Range("A1")
.AutoFilter Field:=1, Criteria1:="=*" & AC & "*"
End With
iRow = 2
Do Until IsEmpty(Cells(iRow, 2))
If Rows(iRow).Hidden = False Then ComboBox1.AddItem Cells(iRow, 2).Value
iRow = iRow + 1
Loop
If ComboBox1.ListCount > 0 Then ComboBox1.ListIndex = 0
End Sub

Anzeige
Danke Reinhard oT
Erich
OT

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige