Live-Forum - Die aktuellen Beiträge
Datum
Titel
19.04.2024 12:23:24
19.04.2024 11:45:34
Anzeige
Archiv - Navigation
1312to1316
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

Doppelt Werte einfärben ....

Doppelt Werte einfärben ....
15.05.2013 18:30:06
Chris
Hallo zusammen,
ich habe folgendes Makro das mir doppelte Werte in Spalte A einfärbt. Ich bräuchte eine Änderung, bekomme das jedoch nicht hin...
A) Auf mehrere Spalten ausdehnen: Von Spalte B (!), jede 6. also H, N, T usw. (oder ist es jetzt jede 7.?), Buchstaben stimmen auf jeden Fall.
B) Wenn doppelte Einträge gefunden, färbe sowohl die Einträge als auch die 5 Zellen, die jeweils neben dem doppelten Werten stehen.
Bsp: B10: 1234 als doppelter Wert, Färbung: B10, C10, D10, F10, G10
Offset ist für letzteres wohl das falsche, wie ich feststellte...
Option Explicit
Public Sub Doppelte_Rot()
Dim lngZeile As Long
Dim lngZeilenSprung As Long
Dim strSuchwert As String
lngZeile = Cells(Rows.Count, 1).End(xlUp).Row
For lngZeilenSprung = lngZeile To 1 Step -1
strSuchwert = Cells(lngZeilenSprung, 1).Value
If Application.WorksheetFunction.CountIf(Range(Cells(1, 1), Cells(lngZeile, 1)),  _
strSuchwert)  1 Then
Cells(lngZeilenSprung, 1).Interior.ColorIndex = 3
Cells(lngZeilenSprung, 1).Offset(, 3).Interior.ColorIndex = 3
End If
Next lngZeilenSprung
End Sub

Chris

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

Betreff
Datum
Anwender
Anzeige
Doppelte Zeilen einfärben
15.05.2013 19:49:20
Erich
Hi Chris,
das würde ich wohl nicht so machen - eher per bedingter Formatierung in Excel.
Ohne zu viel an deinem Code zu ändern:

Public Sub Doppelte_Rot()
Dim lngZeile As Long
Dim lngZeilenSprung As Long
Dim strSuchwert As String
Dim lngSp As Long
lngZeile = Cells(Rows.Count, 1).End(xlUp).Row
For lngSp = 1 To Cells(1, Columns.Count).End(xlToLeft).Column Step 7
For lngZeilenSprung = 1 To lngZeile
strSuchwert = Cells(lngZeilenSprung, lngSp).Value
If strSuchwert > "" Then
If Application.WorksheetFunction.CountIf( _
Range(Cells(1, lngSp), Cells(lngZeile, lngSp)), strSuchwert)  1 Then
Cells(lngZeilenSprung, lngSp).Resize(, 5).Interior.ColorIndex = 3
End If
End If
Next lngZeilenSprung
Next lngSp
End Sub
Rückmeldung wäre nett! - Grüße aus Kamp-Lintfort von Erich

Anzeige
und noch eine Variante...
15.05.2013 19:55:38
Erich
Hi Chris,
beim Resize in der vorigen Version war ein Fehler: Statt (, 5) muss da (, 6) stehen.
Hier noch eine Version:

Public Sub Doppelte_Rot()
Dim lngLastZ As Long
Dim lngZeile As Long
Dim strSuchwert As String
Dim lngSp As Long
lngLastZ = Cells(Rows.Count, 1).End(xlUp).Row
For lngSp = 1 To Cells(1, Columns.Count).End(xlToLeft).Column Step 7
For lngZeile = 1 To lngLastZ
strSuchwert = Cells(lngZeile, lngSp).Value
If strSuchwert > "" Then
If Application.WorksheetFunction.CountIf(Cells(1, lngSp). _
Resize(lngLastZ), strSuchwert)  1 Then
Cells(lngZeile, lngSp).Resize(, 6).Interior.ColorIndex = 3
End If
End If
Next lngZeile
Next lngSp
End Sub
Rückmeldung wäre nett! - Grüße aus Kamp-Lintfort von Erich

Anzeige
AW: und noch eine Variante...
15.05.2013 20:24:08
Chris
Hi
richtig, statt 5, 6 :-)
Aber: Ich habe eines nicht bedacht. Das Makro überprüft ja nun ganze spalten. Ich habe jedoch überschritten in den Spalten stehen, da hat das Makro wohl ein Problem mit, da auch verbundene Zellen:
Das Makro soll ab Spalte B, H, N usw zwar die Spalten durchsuchen, aber erst ab B16...bis ganz unten, H16...bis gaaanz unten, dann N16...bis gaaaanz unten usw.
Sub Doppelte_Rot()
Dim lngZeile As Long
Dim lngZeilenSprung As Long
Dim strSuchwert As String
Dim lngSp As Long
lngZeile = Cells(Rows.Count, 1).End(xlUp).Row
For lngSp = 2 To Cells(1, Columns.Count).End(xlToLeft).Column Step 6
For lngZeilenSprung = 1 To lngZeile
strSuchwert = Cells(lngZeilenSprung, lngSp).Value
If strSuchwert > "" Then
If Application.WorksheetFunction.CountIf( _
Range(Cells(1, lngSp), Cells(lngZeile, lngSp)), strSuchwert)  1 Then
Cells(lngZeilenSprung, lngSp).Resize(, 6).Interior.ColorIndex = 3
End If
End If
Next lngZeilenSprung
Next lngSp
End Sub

Anzeige
und die Nummer 3
16.05.2013 00:57:31
Erich
Hi Chris,
passt das?

Option Explicit
Public Sub Doppelte_Rot3()
Dim lngLastZ As Long
Dim lngZeile As Long
Dim strSuchwert As String
Dim lngSp As Long
For lngSp = 2 To LetzteSpalteTab() Step 6
lngLastZ = Cells(Rows.Count, lngSp).End(xlUp).Row
If lngLastZ > 16 Then
For lngZeile = 16 To lngLastZ
strSuchwert = Cells(lngZeile, lngSp).Value
If strSuchwert > "" Then
If Application.WorksheetFunction.CountIf(Cells(16, lngSp). _
Resize(lngLastZ), strSuchwert)  1 Then
Cells(lngZeile, lngSp).Resize(, 6).Interior.ColorIndex = 3
End If
End If
Next lngZeile
End If
Next lngSp
End Sub
Function LetzteSpalteTab(Optional bChar As Boolean = False)
Dim rng As Range
Set rng = Cells.Find("*", Cells(1, 1), xlValues, , xlByColumns, xlPrevious)
If rng Is Nothing Then
If bChar Then LetzteSpalteTab = "" Else LetzteSpalteTab = 0
Else
If bChar Then
LetzteSpalteTab = SpalteNum2Txt(rng.Column)
Else
LetzteSpalteTab = rng.Column
End If
End If
End Function
Function SpalteNum2Txt(iNr As Long) As String
SpalteNum2Txt = Replace(Cells(1, iNr).Address(0, 0), "1", "")
End Function
Rückmeldung wäre nett! - Grüße aus Kamp-Lintfort von Erich
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige