Gruppe
Dialog
Bereich
RefEdit
Thema
Über UserForm-RefEdit-Steuerelement Bereich auswählen
Problem
Wie kann ich über ein UserForm-RefEdit-Steuerelement einen Bereich auswählen und für den ausgewählten Bereich eine bedingte Formatierung festlegen?
Lösung
Geben Sie den nachfolgenden Code in das Klassenmodul der UserForm ein.
ClassModule: frmFormatierung
Private Sub cmdFormat_Click()
With Range(refFormat.Value)
.FormatConditions.Delete
.Range(refFormat.Value).Cells(1).Activate
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=WOCHENTAG(" & Range(refFormat.Value).Cells(1, 1) _
.Address(False, False) & ")=7"
.FormatConditions(1).Interior.ColorIndex = 35
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=WOCHENTAG(" & Range(refFormat.Value).Cells(1, 1) _
.Address(False, False) & ")=1"
.FormatConditions(2).Interior.ColorIndex = 42
End With
Unload Me
End Sub
Private Sub cmdWeiter_Click()
Unload Me
End Sub
StandardModule: basMain
Sub CallForm()
frmFormatierung.Show
End Sub