AW: Dropdown via VBA zuweisen
31.08.2017 15:11:57
yummi
Hallo key,
du musst von R5 bis R15 noch eine Datenüberprüfung anlegen.
dann den Code:
Private Sub DropDown_aktualisieren()
Dim RNG1 As Range, WS, Z, strFilter1 As String
Dim RNG2 As Range, strFilter2 As String
On Error GoTo Fehler
Set RNG1 = Range("D6:D100")
Set RNG2 = Range("R6:R14")
Me.Unprotect
Application.EnableEvents = False
strFilter1 = ""
strFilter2 = ""
For Each WS In ActiveWorkbook.Sheets
Select Case WS.Name
Case "Summe Luftleistung"
'Diese Blätter nicht ins DropDown
Case "Summe Druck"
Case Else
If Application.WorksheetFunction.CountIf(RNG1, WS.Name) = 0 Then
If WS.Cells(1, 1).Value = "Druck" Then
strFilter1 = strFilter1 & WS.Name & ","
End If
End If
If Application.WorksheetFunction.CountIf(RNG2, WS.Name) = 0 Then
If WS.Cells(1, 1).Value = "Luft" Then
strFilter2 = strFilter2 & WS.Name & ","
End If
End If
End Select
Next
If strFilter1 "" Then
With RNG1.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=strFilter1
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
Else 'Es sind bereits alle Produkte ausgewählt
With RNG1.Validation
.Delete
End With
MsgBox "Es sind bereits alle Produkte ausgewählt"
End If
If strFilter2 "" Then
With RNG2.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=strFilter2
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
Else 'Es sind bereits alle Produkte ausgewählt
With RNG2.Validation
.Delete
End With
MsgBox "Es sind bereits alle Produkte ausgewählt"
End If
Fehler:
If Err.Number 0 Then MsgBox "Fehler: " & _
Err.Number & vbLf & Err.Description: Err.Clear
Me.Protect
Application.EnableEvents = True
End Sub
Gruß
yummi