Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1712to1716
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
Inhaltsverzeichnis

Bedingte Formatierung per VBA mit Schleife

Bedingte Formatierung per VBA mit Schleife
25.09.2019 15:09:59
Dirk
Hallo Zusammen,
ich arbeite derzeit an eine Urlaubsliste (Excel 2010) und möchte per VBA eine bedingte Formatierung realisieren die 1 Halbjahr, als ca. 180 Einträge auf einen Schlag formatiert :
Dies für eine Spalte :

Sub Makro2()
' Makro2 Makro
Range("H2:H21").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$H$2=""So"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub

Ich würde nun gerne eine Schleife hinzufügen, welche diese Formatierung um eine Spalte verschiebt (addiert) und dann anwendet, bis 180 Spalten (von Spalte H bis Spalte GG) abgearbeitet sind.
Für eure Hilfe im Vorfeld schon mal herzlichen Dank....

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Bedingte Formatierung per VBA mit Schleife
25.09.2019 15:54:35
Klaus

Sub Makro2()
' Makro2 Makro
For i=1 to 180
Range(Cells(2,7+i),Cells(21,7+i).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$H$2=""So"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
next i
End Sub

AW: Bedingte Formatierung per VBA mit Schleife
25.09.2019 15:55:41
Klaus
Die Klammer geschlossen fehlt noch bei der Selection..
AW: Bedingte Formatierung per VBA mit Schleife
25.09.2019 16:05:58
Steve

Sub Makro2()
' Makro2 Makro
For i=1 to 180
With Range(Cells(2,7+i),Cells(21,7+i)
.FormatConditions.Add Type:=xlExpression, Formula1:="=$H$2=""So""" .FormatConditions(. _
FormatConditions.Count).SetFirstPriority
.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.FormatConditions(1).StopIfTrue = False
End with
next i
End Sub
Versuchs mal so is kürzer der makrorekorder nimmt viel Mist mit auf
Anzeige
AW: Bedingte Formatierung per VBA mit Schleife
25.09.2019 17:17:02
Dirk
Vielen Dank an Klaus und auch an Steve,
Das Skript von Klaus hat auf Anhieb funktioniert.
Bei Steves Vorschlag fing der Editor hier an zu meckern :
.FormatConditions.Add Type:=xlExpression, Formula1:="=$H$2=""So""" .FormatConditions(. _
FormatConditions.Count).SetFirstPriority
(Fehler beim Kompilieren - Syntaxfehler)
Wie dem auch sei: Auf jeden Fall bedanke ich mich sehr schnelle und effektive Hilfe...Top

303 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige