Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Coloring duplicates based on values in a column.

Hello,
I have a spreadsheet with a macro I wrote in VBA to color duplicate
values. It works well but I have been trying to re-write the macro so that
the colors are alternating. Whereas it colors the first set of duplicates 1
color and then the second set of dupes a different color. Back and forth all
the way up the spreadsheet from the bottom of the UsedRange. Is there a way
to do this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Coloring duplicates based on values in a column.



"Josh" wrote:

Hello,
I have a spreadsheet with a macro I wrote in VBA to color duplicate
values. It works well but I have been trying to re-write the macro so that
the colors are alternating. Whereas it colors the first set of duplicates 1
color and then the second set of dupes a different color. Back and forth all
the way up the spreadsheet from the bottom of the UsedRange. Is there a way
to do this?


I also forgot to put that I am coloring the EntireRow.

Thanks!
Josh
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Coloring duplicates based on values in a column.

looks like you forgot to post the code you are using also. <g

"Josh" wrote:



"Josh" wrote:

Hello,
I have a spreadsheet with a macro I wrote in VBA to color duplicate
values. It works well but I have been trying to re-write the macro so that
the colors are alternating. Whereas it colors the first set of duplicates 1
color and then the second set of dupes a different color. Back and forth all
the way up the spreadsheet from the bottom of the UsedRange. Is there a way
to do this?


I also forgot to put that I am coloring the EntireRow.

Thanks!
Josh

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Coloring duplicates based on values in a column.

I have a spreadsheet with a macro I wrote in VBA to color duplicate
values. It works well but I have been trying to re-write the macro so
that
the colors are alternating. Whereas it colors the first set of duplicates
1
color and then the second set of dupes a different color. Back and forth
all
the way up the spreadsheet from the bottom of the UsedRange. Is there a
way
to do this?


I also forgot to put that I am coloring the EntireRow.


It sounds like you already have created the row coloring code, so I'll
assume that is in place. Below is a structure you can use to alternate
colors. Note that I have used a CommandButton Click event to house the code
structure, but you would place the code structure in whatever function or
procedure is appropriate for you macro.

Enum Colors
FirstColor = 15366924 ' RGB(012,123,234)
SecondColor = 818154 ' RGB(234,123,012)
End Enum

Private Sub CommandButton1_Click()
Static Color As Long
Const ColorSum As Long = Colors.FirstColor + Colors.SecondColor
If Color = 0 Then Color = Colors.FirstColor
Color = ColorSum - Color
'
' Your code that uses alternating colors goes here
'
End Sub

Here I have used to arbitrary colors to alternate between.... substitute
your own colors for the two I used (they only have to be set in the Enum).
You could, if you want, eliminate the Enum and place your color values
directly inside the procedure, but I think the code is more self-documenting
with the Enum. Anyway, each time the procedure containing this code
structure is executed, the static Color 'variable will contain the opposite
color from the one used the last time the procedure was executed.

Rick

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Coloring duplicates based on values in a column.

Thanks Rick. Here is my code for coloring the dupes. I have just recently
been teaching myself VBA so I'm sure there would have been an easier way to
color the duplicates that is universal and not based on a specific column
within the code. Please take a look and see if there is something that can be
simplified and how your code would work within. Thanks.

Sub ColorAlternates()
Dim MyRange As String
Dim F As Boolean
Dim MyCount As Integer
Dim MyCount2 As Integer
Dim MyCount3 As Integer
MyCount = ActiveSheet.UsedRange.Rows.Count
MyCount2 = ActiveSheet.UsedRange.Rows.Count - 1
MyCount3 = ActiveSheet.UsedRange.Rows.Count
MsgBox (MyCount & " " & MyCount2)
Dim i As Integer
For i = MyCount To 3 Step -1
If Cells(MyCount, "B").Value = Cells(MyCount2, "B").Value Then
Cells(MyCount, "B").EntireRow.Interior.ColorIndex = 10
Cells(MyCount2, "B").EntireRow.Interior.ColorIndex = 10
End If
MyCount = MyCount - 1
MyCount2 = MyCount2 - 1
Next i
For i = MyCount3 To 3 Step -1
If Cells(MyCount3, "B").Value = Cells(MyCount3 - 1, "B").Value And
Cells(MyCount3, "B").EntireRow.Interior.ColorIndex = Cells(MyCount3 - 1,
"B").EntireRow.Interior.ColorIndex And F = True Then
Cells(MyCount, "B").EntireRow.Interior.ColorIndex = 15
Cells(MyCount, "B").EntireRow.Interior.ColorIndex = 15
F = False
GoTo EndLine
ElseIf Cells(MyCount3, "B").Value = Cells(MyCount3 - 1, "B").Value
And Cells(MyCount3, "B").EntireRow.Interior.ColorIndex = Cells(MyCount3 - 1,
"B").EntireRow.Interior.ColorIndex And F = False Then
Cells(MyCount3, "B").EntireRow.Interior.ColorIndex = 10
Cells(MyCount3, "B").EntireRow.Interior.ColorIndex = 10
F = True
End If
EndLine:
Next i
End Sub



"Rick Rothstein (MVP - VB)" wrote:

I have a spreadsheet with a macro I wrote in VBA to color duplicate
values. It works well but I have been trying to re-write the macro so
that
the colors are alternating. Whereas it colors the first set of duplicates
1
color and then the second set of dupes a different color. Back and forth
all
the way up the spreadsheet from the bottom of the UsedRange. Is there a
way
to do this?


I also forgot to put that I am coloring the EntireRow.


It sounds like you already have created the row coloring code, so I'll
assume that is in place. Below is a structure you can use to alternate
colors. Note that I have used a CommandButton Click event to house the code
structure, but you would place the code structure in whatever function or
procedure is appropriate for you macro.

Enum Colors
FirstColor = 15366924 ' RGB(012,123,234)
SecondColor = 818154 ' RGB(234,123,012)
End Enum

Private Sub CommandButton1_Click()
Static Color As Long
Const ColorSum As Long = Colors.FirstColor + Colors.SecondColor
If Color = 0 Then Color = Colors.FirstColor
Color = ColorSum - Color
'
' Your code that uses alternating colors goes here
'
End Sub

Here I have used to arbitrary colors to alternate between.... substitute
your own colors for the two I used (they only have to be set in the Enum).
You could, if you want, eliminate the Enum and place your color values
directly inside the procedure, but I think the code is more self-documenting
with the Enum. Anyway, each time the procedure containing this code
structure is executed, the static Color 'variable will contain the opposite
color from the one used the last time the procedure was executed.

Rick




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Coloring duplicates based on values in a column.

Thanks Rick. Here is my code for coloring the dupes. I have just recently
been teaching myself VBA so I'm sure there would have been an easier way
to
color the duplicates that is universal and not based on a specific column
within the code. Please take a look and see if there is something that can
be
simplified and how your code would work within. Thanks.


Here is the concept behind my code (modified to account for how you are
selecting your colors and embedded directly into the subroutine) used to
alternately color rows 3 through 100 (your post said to start at 3; I chose
100 as a limit, but you can specify whatever row value you want in the For
loop's "To" value)...

Sub ColorAlternates()
Dim X As Long
Dim IndexValue As Long
' The sum of your two specified indexes - 10 and 15
Const ColorSum As Long = 25
' Specify the start color index
IndexValue = 10
For X = 3 To 100 ' Change 100 to maximum row value desired
Range("A" & X).EntireRow.Interior.ColorIndex = IndexValue
IndexValue = ColorSum - IndexValue
Next
End Sub


Rick

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Coloring duplicates based on values in a column.

Hi Rick,
Coloring alternate records isn't the problem...the problem is that I want to
color duplicate rows alternately. Let me know if this makes better sense,
thanks!

"Rick Rothstein (MVP - VB)" wrote:

Thanks Rick. Here is my code for coloring the dupes. I have just recently
been teaching myself VBA so I'm sure there would have been an easier way
to
color the duplicates that is universal and not based on a specific column
within the code. Please take a look and see if there is something that can
be
simplified and how your code would work within. Thanks.


Here is the concept behind my code (modified to account for how you are
selecting your colors and embedded directly into the subroutine) used to
alternately color rows 3 through 100 (your post said to start at 3; I chose
100 as a limit, but you can specify whatever row value you want in the For
loop's "To" value)...

Sub ColorAlternates()
Dim X As Long
Dim IndexValue As Long
' The sum of your two specified indexes - 10 and 15
Const ColorSum As Long = 25
' Specify the start color index
IndexValue = 10
For X = 3 To 100 ' Change 100 to maximum row value desired
Range("A" & X).EntireRow.Interior.ColorIndex = IndexValue
IndexValue = ColorSum - IndexValue
Next
End Sub


Rick


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter duplicates based on criteria / column values phillr Excel Discussion (Misc queries) 0 April 9th 10 09:13 PM
Conditional coloring of Excel cells, based on adjacent cell values? Greg Stuart Excel Worksheet Functions 0 March 10th 06 10:14 PM
Concat values in two or more rows based on id and eliminate duplicates italia Excel Programming 2 October 19th 05 06:33 PM
Coloring the duplicates with VBA Bobby Excel Programming 5 November 18th 04 11:11 PM
Calculating values to column D with formula based on values column A spolk[_2_] Excel Programming 1 April 30th 04 06:29 PM


All times are GMT +1. The time now is 03:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"