ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to change color (https://www.excelbanter.com/excel-programming/306672-how-change-color.html)

eric

How to change color
 
Hello,

I have a problem writing a macro in my excel file, I want
to change the color of specific range and my data goes
like this:
Column1 Column2
Row 1: Filename ABC
Row 2: Desc ABC Company
..
..
..
Row 21: Filename DEF
Row 22: Desc DEF Enterprise
..
..
..
so on

I have to search for word "Filename" and if found, change
the "ABC" color to RED and go down change "ABC Company" to
Blue, and so on. Below is sample code, How could I do
this in loop (in Do While perhaps?) so that my code won't
be long.

Cells.Find(What:="Filename", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate
Range("B5").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 5
Range("B6").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 10
Range("B7").Select
Selection.Font.Bold = True
Range("B8").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 3
Cells.FindNext(After:=ActiveCell).Activate
Range("B75").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 5
Range("B76").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 10
Range("B77").Select
Selection.Font.Bold = True
Range("B78").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 3

Thanks everybody in advance for your help.
Eric




No Name

How to change color
 
You can try using something like that

if Cells(RowIndex,Coulnm1)= "Filename" Then
Cells(RowIndex,Coulnm).interior.colorindex=3 And
Cells(RowIndex,Coulnm).interior.colorindex=5

And put it in the loop...


-----Original Message-----
Hello,

I have a problem writing a macro in my excel file, I

want
to change the color of specific range and my data goes
like this:
Column1 Column2
Row 1: Filename ABC
Row 2: Desc ABC Company
..
..
..
Row 21: Filename DEF
Row 22: Desc DEF Enterprise
..
..
..
so on

I have to search for word "Filename" and if found,

change
the "ABC" color to RED and go down change "ABC Company"

to
Blue, and so on. Below is sample code, How could I do
this in loop (in Do While perhaps?) so that my code

won't
be long.

Cells.Find(What:="Filename", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate
Range("B5").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 5
Range("B6").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 10
Range("B7").Select
Selection.Font.Bold = True
Range("B8").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 3
Cells.FindNext(After:=ActiveCell).Activate
Range("B75").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 5
Range("B76").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 10
Range("B77").Select
Selection.Font.Bold = True
Range("B78").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 3

Thanks everybody in advance for your help.
Eric



.


...Patrick[_3_]

How to change color
 
Look at the conditionnal format


Pat

"Eric" a écrit dans le message de
...
Hello,

I have a problem writing a macro in my excel file, I want
to change the color of specific range and my data goes
like this:
Column1 Column2
Row 1: Filename ABC
Row 2: Desc ABC Company
.
.
.
Row 21: Filename DEF
Row 22: Desc DEF Enterprise
.
.
.
so on

I have to search for word "Filename" and if found, change
the "ABC" color to RED and go down change "ABC Company" to
Blue, and so on. Below is sample code, How could I do
this in loop (in Do While perhaps?) so that my code won't
be long.

Cells.Find(What:="Filename", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate
Range("B5").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 5
Range("B6").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 10
Range("B7").Select
Selection.Font.Bold = True
Range("B8").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 3
Cells.FindNext(After:=ActiveCell).Activate
Range("B75").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 5
Range("B76").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 10
Range("B77").Select
Selection.Font.Bold = True
Range("B78").Select
Selection.Font.Bold = True
Selection.Font.ColorIndex = 3

Thanks everybody in advance for your help.
Eric







All times are GMT +1. The time now is 07:41 PM.

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