LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Coloring cells with same values using VBA?

Hi,

You could first pull a unique list of your Excel Column. Loop through
your unique list and compare each value in the excel column. If it
matches, color it, else skip. Here's some sample code: "Values" is the
range which has all the Excel column entries. "Extracts" is the range
to which unique values are extracted.

Sub Test()

Dim intUniqueCounter As Integer, intRowCounter As Integer,
intUniqueValue As Integer
Dim intColor As Integer

intColor = 5

'Filter unique list of values
Range("Values").AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range("Extract" _
), Unique:=True

'Loop through each unique value
For intUniqueCounter = 1 To Range("Extract").CurrentRegion.Rows.Count
- 1

'Increment color with each unique value
intColor = intColor + 1
intUniqueValue =
Range("Extract").CurrentRegion.Cells(intUniqueCoun ter + 1, 1).Value

'Loop through each cell in column
For intRowCounter = 1 To Range("Values").CurrentRegion.Rows.Count
- 1

'Compare values
If Range("Values").Cells(intRowCounter + 1, 1).Value =
intUniqueValue Then

Range("Values").Cells(intRowCounter + 1, 1).Select
With Selection.Interior
.ColorIndex = intColor
.Pattern = xlSolid
End With
End If
Next
Next
End Sub


Hope this helps!

Varsha
Hi,

Say in an Excel column I have this:

B1 12
B2 12
B3 4
B4 7
B5 4
B6 12
B7 7

and want to use a VBA piece of code to give same color to those with
same value. How can I do so please?

Regards,
Mike

 
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
Coloring cells OldManEd Excel Discussion (Misc queries) 8 June 4th 10 05:44 AM
coloring cells 6371 New Users to Excel 2 April 22nd 09 04:26 AM
Conditional coloring of Excel cells, based on adjacent cell values? Greg Stuart Excel Worksheet Functions 0 March 10th 06 10:14 PM
COLORING IN CELLS jim mcgrath Excel Discussion (Misc queries) 4 November 24th 05 04:31 PM
Coloring certain cells Tim Excel Worksheet Functions 2 September 5th 05 04:01 AM


All times are GMT +1. The time now is 11:31 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"