ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Highlight row a random color (https://www.excelbanter.com/excel-worksheet-functions/188353-highlight-row-random-color.html)

Altan

Highlight row a random color
 
Visual Basic 6.3/Excel 2003/XP

(Function Question 1)

Column A- has many different ticket numbers sometimes duplicated. Can I
create code to have all duplicated ticket numbers highlighted a random color?
Then hightlight the entire row whatever color that is?

For ex: I would like 1456 on both rows to be any random color that will
continue from Column A to Column F.

Column A Column B ... Column F
1456 NMS Work in Progress
1489 BO Scheduled
1456 Staffed New
1789 NMS Scheduled


(Function Question 2)

Column D has date and time. What code will color the entire row that
matches date and time?

For ex: 5/1/2008 9:00 make this entire row from 1456 (Column A) xColor &
1789 (Column A) That same color.

Column A... Column D ... Column F
1456 5/1/2008 9:00 Work in Progress
1489 5/8/2008 19:00 Scheduled
1456 5/30/2008 3:00 New
1789 5/1/2008 9:00 Scheduled

Thank you for your time....

-Altan


Gary''s Student

Highlight row a random color
 
Try this small macro:

Sub altan()
n = Cells(Rows.Count, "A").End(xlUp).Row
v1 = 1
v2 = 56
Set r = Range("A:A")
For i = 1 To n
Set r2 = Cells(i, 1)
m = Application.WorksheetFunction.CountIf(r, r2)
If m 1 Then
p = Int(((v2 - v1 + 1) * Rnd) + v1)
Cells(i, 1).EntireRow.Interior.ColorIndex = p
End If
Next
End Sub
--
Gary''s Student - gsnu200787


"Altan" wrote:

Visual Basic 6.3/Excel 2003/XP

(Function Question 1)

Column A- has many different ticket numbers sometimes duplicated. Can I
create code to have all duplicated ticket numbers highlighted a random color?
Then hightlight the entire row whatever color that is?

For ex: I would like 1456 on both rows to be any random color that will
continue from Column A to Column F.

Column A Column B ... Column F
1456 NMS Work in Progress
1489 BO Scheduled
1456 Staffed New
1789 NMS Scheduled


(Function Question 2)

Column D has date and time. What code will color the entire row that
matches date and time?

For ex: 5/1/2008 9:00 make this entire row from 1456 (Column A) xColor &
1789 (Column A) That same color.

Column A... Column D ... Column F
1456 5/1/2008 9:00 Work in Progress
1489 5/8/2008 19:00 Scheduled
1456 5/30/2008 3:00 New
1789 5/1/2008 9:00 Scheduled

Thank you for your time....

-Altan


[email protected]

Quote:

Originally Posted by Gary''s Student (Post 669414)
Try this small macro:

Sub altan()
n = Cells(Rows.Count, "A").End(xlUp).Row
v1 = 1
v2 = 56
Set r = Range("A:A")
For i = 1 To n
Set r2 = Cells(i, 1)
m = Application.WorksheetFunction.CountIf(r, r2)
If m 1 Then
p = Int(((v2 - v1 + 1) * Rnd) + v1)
Cells(i, 1).EntireRow.Interior.ColorIndex = p
End If
Next
End Sub
--
Gary''s Student - gsnu200787
[/i][/color]

********************************************
Hey Gary"s...

I love the script but have one question/request.
When I ran it-it highlighted each duplicate a different color.
Is there any way to have it randomly color each SET of duplicates?
thanks, -h


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com