For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > July 2006 > Row colour









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Row colour
stardust99_fr@yahoo.fr

2006-06-30, 7:56 am

I am using an excel document which contains a column called "Colour"
I'd like to know how to apply this colour to the row containing this
colour.
I'm using the following code so far, but the whole row has the color
applied, even if there is no data inside the cells of this row. How do
i change it for applying it only to the cells that are populated.

For Each Cell In Range("A1:" &
Cells.SpecialCells(xlCellTypeLastCell).Address)
If CStr(Trim(Cell.Value)) = "orange" Then
Sheet1.Rows(1).Interior.Color = &HC0FFFF
End If

If CStr(Trim(Cell.Value)) = "yellow" Then
Sheet1.Rows(1).Interior.Color = RGB(0, 0, 255)
End If

Next Cell

As i am new to VB any help would be great
Thanks in advance
Faby

Peter T

2006-07-02, 7:55 am

Your code is VBA, try re-posting your question in this newsgroup -

news.microsoft.public.excel.programming

FWIW, you are only applying a format to Row 1 regardless of the cell that
contains your condition, probably Sheet1.Rows(cell.row).etc. However your
code would benefit from total re-write, I'm sure you'll get suggestions in
the Excel group.

Regards,
Peter T

<stardust99_fr@yahoo.fr> wrote in message
news:1151672012.482629.220770@b68g2000cwa.googlegroups.com...
> I am using an excel document which contains a column called "Colour"
> I'd like to know how to apply this colour to the row containing this
> colour.
> I'm using the following code so far, but the whole row has the color
> applied, even if there is no data inside the cells of this row. How do
> i change it for applying it only to the cells that are populated.
>
> For Each Cell In Range("A1:" &
> Cells.SpecialCells(xlCellTypeLastCell).Address)
> If CStr(Trim(Cell.Value)) = "orange" Then
> Sheet1.Rows(1).Interior.Color = &HC0FFFF
> End If
>
> If CStr(Trim(Cell.Value)) = "yellow" Then
> Sheet1.Rows(1).Interior.Color = RGB(0, 0, 255)
> End If
>
> Next Cell
>
> As i am new to VB any help would be great
> Thanks in advance
> Faby
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com