Private Sub ComboBox2_DropButtonClick()
ActiveCell.Value = ComboBox2.Value
End Sub
in meine aktive Zelle reingeschrieben. So nun das Problem.
Jedesmal, wenn ich nun die Combobox mit dem Pfeil nach unten öffnen will, wird der Code bereits ausgeführt. Danach habe ich mal das Click-Ereignis aubrobiert, da reagiert der Code aber garnicht.
Was für ein Ereignis muss ich wählen, damit der Code erst ausgeführt wird, wenn ich tatsächlich in die Auswahlliste der Combobox klicke, also wenn ich wirklich eine Auswahl getroffen habe und nicht bereits, wenn ich die Combobox überhaupt nur anklicke.
Danke mal
Gruss
Joachim
Private Sub Worksheet_Activate()
Call Fuellen
End Sub
Sub Fuellen()
Application.EnableEvents = False
Dim dic As Object
Dim xKey As Variant
Dim iRow As Long, CLetzte As Long
ComboBox1.Clear
CLetzte = IIf(IsEmpty(Range("C65536")), Range("C65536").End(xlUp).Row, 65536)
Set dic = CreateObject("scripting.dictionary")
For iRow = 1 To CLetzte
If Not IsEmpty(Cells(iRow, 3)) Then
xKey = Cells(iRow, 3).Value
dic(xKey) = 0
End If
Next
For Each xKey In dic
ComboBox1.AddItem xKey
Next
dic.RemoveAll
Set dic = Nothing
Call Sortieren1
ComboBox1.ListIndex = 0
Application.EnableEvents = True
End Sub
Sub Sortieren1()
Dim Letzter As Integer, Naechster As Integer
Dim i As String
With ComboBox1
For Letzter = 0 To .ListCount - 1
For Naechster = Letzter + 1 To .ListCount - 1
If .List(Letzter) > .List(Naechster) Then
i = .List(Letzter)
.List(Letzter) = .List(Naechster)
.List(Naechster) = i
End If
Next Naechster
Next Letzter
End With
End Sub
Option Explicit
Dim Aktion As Boolean
Private Sub ComboBox1_Click()
If Aktion = True Then Exit Sub
Debug.Print ComboBox1.Text
End Sub
Private Sub Worksheet_Activate()
Call Fuellen
End Sub
Sub Fuellen()
Dim dic As Object
Dim xKey As Variant
Dim iRow As Long, CLetzte As Long
ComboBox1.Clear
CLetzte = IIf(IsEmpty(Range("C65536")), Range("C65536").End(xlUp).Row, 65536)
Set dic = CreateObject("scripting.dictionary")
For iRow = 1 To CLetzte
If Not IsEmpty(Cells(iRow, 3)) Then
xKey = Cells(iRow, 3).Value
dic(xKey) = 0
End If
Next
For Each xKey In dic
ComboBox1.AddItem xKey
Next
dic.RemoveAll
Set dic = Nothing
Call Sortieren1
Aktion = True
ComboBox1.ListIndex = 0
Aktion = False
End Sub
Sub Sortieren1()
Dim Letzter As Integer, Naechster As Integer
Dim i As String
With ComboBox1
For Letzter = 0 To .ListCount - 1
For Naechster = Letzter + 1 To .ListCount - 1
If .List(Letzter) > .List(Naechster) Then
i = .List(Letzter)
.List(Letzter) = .List(Naechster)
.List(Naechster) = i
End If
Next Naechster
Next Letzter
End With
End Sub
Gruß Tino
www.excelvba.eu
Private Sub ComboBox1_Click()
If Aktion = True Then Exit Sub
Debug.Print ComboBox1.Text
ActiveCell.Value = ComboBox1.Value
End Sub
Private Sub ComboBox2_Click()
If Aktion = True Then Exit Sub
Debug.Print ComboBox2.Text
Sheets("Initialien").Range("H1") = Me.ComboBox2.Value
ActiveCell.Value = Sheets("Initialien").Range("I1")
End Sub
Private Sub Worksheet_Activate()
Call Fuellen
Call Fuellen2
End Sub
Sub Fuellen()
Aktion = True
Dim dic As Object
Dim xKey As Variant
Dim iRow As Long, CLetzte As Long
ComboBox1.Clear
CLetzte = IIf(IsEmpty(Range("C65536")), Range("C65536").End(xlUp).Row, 65536)
Set dic = CreateObject("scripting.dictionary")
For iRow = 1 To CLetzte
If Not IsEmpty(Cells(iRow, 3)) Then
xKey = Cells(iRow, 3).Value
dic(xKey) = 0
End If
Next
For Each xKey In dic
ComboBox1.AddItem xKey
Next
dic.RemoveAll
Set dic = Nothing
Call Sortieren1
ComboBox1.ListIndex = 0
Aktion = False
End Sub
Sub Sortieren1()
Dim Letzter As Integer, Naechster As Integer
Dim i As String
With ComboBox1
For Letzter = 0 To .ListCount - 1
For Naechster = Letzter + 1 To .ListCount - 1
If .List(Letzter) > .List(Naechster) Then
i = .List(Letzter)
.List(Letzter) = .List(Naechster)
.List(Naechster) = i
End If
Next Naechster
Next Letzter
End With
End Sub
Sub Fuellen2()
Aktion = True
Dim col As New Collection
Dim iRow As Long, aRow As Long
Dim wksA As Worksheet
Set wksA = ThisWorkbook.Worksheets("Initialien")
aRow = IIf(IsEmpty(wksA.Cells(65536, 1)), wksA.Cells(65536, 1).End(xlUp).Row, 65536)
On Error Resume Next
ComboBox2.Clear
For iRow = 1 To aRow
If Not IsEmpty(wksA.Cells(iRow, 1)) Then
col.Add wksA.Cells(iRow, 1), wksA.Cells(iRow, 1)
If Err = 0 Then
ComboBox2.AddItem wksA.Cells(iRow, 1)
Else
Err.Clear
End If
End If
Next iRow
On Error GoTo 0
Call Sortieren2
ComboBox2.ListIndex = 0
Aktion = False
End Sub
Sub Sortieren2()
Dim Letzter As Integer, Naechster As Integer
Dim i As String
With ComboBox2
For Letzter = 0 To .ListCount - 1
For Naechster = Letzter + 1 To .ListCount - 1
If .List(Letzter) > .List(Naechster) Then
i = .List(Letzter)
.List(Letzter) = .List(Naechster)
.List(Naechster) = i
End If
Next Naechster
Next Letzter
End With
End Sub
Private Sub ComboBox1_Click()
If Aktion = True Then Exit Sub
Debug.Print ComboBox1.Text
ActiveCell.Value = ComboBox1.Value
End Sub
Private Sub ComboBox2_Click()
If Aktion = True Then Exit Sub
Debug.Print ComboBox2.Text
Sheets("Initialien").Range("H1") = Me.ComboBox2.Value
ActiveCell.Value = Sheets("Initialien").Range("I1")
End Sub
Private Sub Worksheet_Activate()
Call Fuellen
Call Fuellen2
End Sub
Sub Fuellen()
Aktion = True
Dim dic As Object
Dim xKey As Variant
Dim iRow As Long, CLetzte As Long
ComboBox1.Clear
CLetzte = IIf(IsEmpty(Range("C65536")), Range("C65536").End(xlUp).Row, 65536)
Set dic = CreateObject("scripting.dictionary")
For iRow = 1 To CLetzte
If Not IsEmpty(Cells(iRow, 3)) Then
xKey = Cells(iRow, 3).Value
dic(xKey) = 0
End If
Next
For Each xKey In dic
ComboBox1.AddItem xKey
Next
dic.RemoveAll
Set dic = Nothing
Call Sortieren1
ComboBox1.ListIndex = 0
Aktion = False
End Sub
Sub Sortieren1()
Dim Letzter As Integer, Naechster As Integer
Dim i As String
With ComboBox1
For Letzter = 0 To .ListCount - 1
For Naechster = Letzter + 1 To .ListCount - 1
If .List(Letzter) > .List(Naechster) Then
i = .List(Letzter)
.List(Letzter) = .List(Naechster)
.List(Naechster) = i
End If
Next Naechster
Next Letzter
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Aktion = True
ComboBox1.ListIndex = -1
Aktion = False
End Sub
Gruß Tino