Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel rows 1

Status
Not open for further replies.

100dtl

Programmer
Aug 18, 2003
313
GB
Hi

Not sure if i'm in the right forum/...

Is this possible in excel VB module?, if i type in a text value, eg: final

the row then looks at this value and colors the row in a specified colour? I would like different colors for different text values ie:

final1 = red
final2 = green
final3 = yellow
final4 = blue

etc.

MANY THXS in advance
 
Try this:

Cells.Find(What:=YourSearchtext, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
Select Case YourSearchtext
Case "final"
Selection.Font.ColorIndex = 3 'Red
Case "myGreen"
Selection.Font.ColorIndex = 4 'Green
Case "myYellow"
Selection.Font.ColorIndex = 6 'Yellow
Case "myBlue"
Selection.Font.ColorIndex = 5 'Blue
End Select

OK? :)
MakeItSo

Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
Another is if my YourSearchtext was one column, how would i do that?
 
Oh, I thought you already had a macro... ;-)
BTW: The above code is partially non-sense... :-/

Well then:
Go to tools - macros and create a macro, e.g. "ColorIt"
In VB-Editor paste this:

Sub ColorIt()
Dim starter
Dim i As Integer
Dim myCrits As Variant
Dim myColors As Variant
Dim crit As String

myCrits = Array("final", "green", "yellow", "blue")
myColors = Array("3", "4", "6", "5")

For i = 0 To UBound(myCrits)
crit = myCrits(i)
Cells.Find(What:=crit, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
Do While True
Selection.Font.ColorIndex = myColors(i)
Set starter = ActiveCell
Cells.FindNext.Activate
If ActiveCell.Address = starter.Address Then Exit Do
Loop
Next i
End Sub

I've tested it and it seems to work fine... :)
Cheers,
MakeItSo

Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
Cool, well neally, made up with hat you have done but... I want the row to change color not the text :-\ is this possible?
 
I'd like to have it always running aswell.. peeeez
 
trust me - you don't want it always running - how are you gonna work on the sheet if the code is always running and making changes - run it from the worksheet change event and check to see what column has been changed....

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Ok,... no problem, I've put a button on... Anyone help with the colouring of the row?? instead of the text inthe cell?
 
For the row you should use this
Code:
   Selection.EntireRow.Font.ColorIndex = myColors(i)
OR
   Selection.EntireColumn.Font.ColorIndex = myColors(i)

________
George, M
 
OK, here it comes: (I had to change a few lines, so just overwrite your old code with it)

Sub ColorIt()
Dim starter
Dim i As Integer
Dim myCrits As Variant
Dim myColors As Variant
Dim crit As String

myCrits = Array("final", "green", "yellow", "blue")
myColors = Array("3", "4", "6", "5")

For i = 0 To UBound(myCrits)
crit = myCrits(i)
Cells.Find(What:=crit, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
Do While True
Set starter = ActiveCell
Rows(ActiveCell.Row).Select
Selection.Font.ColorIndex = myColors(i)
starter.Select
Cells.FindNext.Activate
If ActiveCell.Address = starter.Address Then Exit Do
Loop
Next i
End Sub

[lightsaber]

MakeItSO

Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
It still did text but thats fine with me, !!! nice one
 
to change the background colour, instead of:

Rows(ActiveCell.Row).Select
Selection.Font.ColorIndex = myColors(i)

use

Rows(ActiveCell.Row).interior.ColorIndex = myColors(i)

in fact, even if you don't want to change from font to background, use this syntax. Select statements are very rarely necessary and they just slow the code down


Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top