PC Review


Reply
Thread Tools Rate Thread

Coloring Rows based on contents of cell A on each row

 
 
Jeff W.
Guest
Posts: n/a
 
      18th Oct 2007
I want to create this sub or macro that will start at row 2 and cell A
test for the a word and if this is found then select the cells on that row
from A to H and change the format adding color to the cells based on
the word found.

This is what I have so far, but it doesnt work...

It runs but it doesnt change anything, I'm lost, I'm not a vba programmer
but this does make sence to me, sort of...

Sub color_rows()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For RowCount = 2 To lastrow
a_num = RowCount 'row index
h_num = RowCount + 7 'cell index

If Cells(RowCount) = "Open" Then ' test for the word "Open"
Cells("a_num:h_num").Select ' select cells A to H in the
current row
With Selection.Interior ' this would change the
format of the selected cells
.ColorIndex = 4
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If

If Cells(RowCount) = "Waiting" Then ' test for the word "Waiting"
Cells("a_num:h_num").Select ' select cells A to H in the
current row
With Selection.Interior ' this would change the
format of the selected cells
.ColorIndex = 27
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If

If Cells(RowCount) = "Closed" Then ' test for the word "Closed"
Cells("a_num:h_num").Select ' select cells A to H in the
current row
Selection.Interior.ColorIndex = xlNone ' this would change the color to
none
End If
Next RowCount
End Sub

If anyone see's something wrong with this, I could sure use the help...

Thanks,

Jeff W.



 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      18th Oct 2007
These won't work becaus you are only referencing the row number. You need to
include the column you want to search. expl: Cells(RowCount, 1) would
search column A.

If Cells(RowCount) = "Open" Then
If Cells(RowCount) = "Waiting" Then

"Jeff W." wrote:

> I want to create this sub or macro that will start at row 2 and cell A
> test for the a word and if this is found then select the cells on that row
> from A to H and change the format adding color to the cells based on
> the word found.
>
> This is what I have so far, but it doesnt work...
>
> It runs but it doesnt change anything, I'm lost, I'm not a vba programmer
> but this does make sence to me, sort of...
>
> Sub color_rows()
> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> For RowCount = 2 To lastrow
> a_num = RowCount 'row index
> h_num = RowCount + 7 'cell index
>
> If Cells(RowCount) = "Open" Then ' test for the word "Open"
> Cells("a_num:h_num").Select ' select cells A to H in the
> current row
> With Selection.Interior ' this would change the
> format of the selected cells
> .ColorIndex = 4
> .Pattern = xlSolid
> .PatternColorIndex = xlAutomatic
> End With
> End If
>
> If Cells(RowCount) = "Waiting" Then ' test for the word "Waiting"
> Cells("a_num:h_num").Select ' select cells A to H in the
> current row
> With Selection.Interior ' this would change the
> format of the selected cells
> .ColorIndex = 27
> .Pattern = xlSolid
> .PatternColorIndex = xlAutomatic
> End With
> End If
>
> If Cells(RowCount) = "Closed" Then ' test for the word "Closed"
> Cells("a_num:h_num").Select ' select cells A to H in the
> current row
> Selection.Interior.ColorIndex = xlNone ' this would change the color to
> none
> End If
> Next RowCount
> End Sub
>
> If anyone see's something wrong with this, I could sure use the help...
>
> Thanks,
>
> Jeff W.
>
>
>
>

 
Reply With Quote
 
Jeff W.
Guest
Posts: n/a
 
      18th Oct 2007
I made the change you suggested but now it wont run without
Error it stops with "Type Mismatch" on the follwoing line;

Cells("a_num:h_num").Select ' select cells A to H in the

I have tried changing this to "Range" rather than "Cells" but the same error

Any ideas?

<Jeff>



"JLGWhiz" <(E-Mail Removed)> wrote in message
news:A0113FE9-7BC6-433C-83A3-(E-Mail Removed)...
> These won't work becaus you are only referencing the row number. You need
> to
> include the column you want to search. expl: Cells(RowCount, 1) would
> search column A.
>
> If Cells(RowCount) = "Open" Then
> If Cells(RowCount) = "Waiting" Then
>
> "Jeff W." wrote:
>
>> I want to create this sub or macro that will start at row 2 and cell A
>> test for the a word and if this is found then select the cells on that
>> row
>> from A to H and change the format adding color to the cells based on
>> the word found.
>>
>> This is what I have so far, but it doesnt work...
>>
>> It runs but it doesnt change anything, I'm lost, I'm not a vba programmer
>> but this does make sence to me, sort of...
>>
>> Sub color_rows()
>> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
>> For RowCount = 2 To lastrow
>> a_num = RowCount 'row index
>> h_num = RowCount + 7 'cell index
>>
>> If Cells(RowCount) = "Open" Then ' test for the word "Open"
>> Cells("a_num:h_num").Select ' select cells A to H in the
>> current row
>> With Selection.Interior ' this would change the
>> format of the selected cells
>> .ColorIndex = 4
>> .Pattern = xlSolid
>> .PatternColorIndex = xlAutomatic
>> End With
>> End If
>>
>> If Cells(RowCount) = "Waiting" Then ' test for the word "Waiting"
>> Cells("a_num:h_num").Select ' select cells A to H in
>> the
>> current row
>> With Selection.Interior ' this would change
>> the
>> format of the selected cells
>> .ColorIndex = 27
>> .Pattern = xlSolid
>> .PatternColorIndex = xlAutomatic
>> End With
>> End If
>>
>> If Cells(RowCount) = "Closed" Then ' test for the word "Closed"
>> Cells("a_num:h_num").Select ' select cells A to H in
>> the
>> current row
>> Selection.Interior.ColorIndex = xlNone ' this would change the color
>> to
>> none
>> End If
>> Next RowCount
>> End Sub
>>
>> If anyone see's something wrong with this, I could sure use the help...
>>
>> Thanks,
>>
>> Jeff W.
>>
>>
>>
>>



 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      18th Oct 2007
On Oct 17, 9:35 pm, "Jeff W." <part_ma...@verizon.net> wrote:
> I made the change you suggested but now it wont run without
> Error it stops with "Type Mismatch" on the follwoing line;
>
> Cells("a_num:h_num").Select ' select cells A to H in the
>
> I have tried changing this to "Range" rather than "Cells" but the same error
>
> Any ideas?
>
> <Jeff>
>
> "JLGWhiz" <JLGW...@discussions.microsoft.com> wrote in message
>
> news:A0113FE9-7BC6-433C-83A3-(E-Mail Removed)...
>
> > These won't work becaus you are only referencing the row number. You need
> > to
> > include the column you want to search. expl: Cells(RowCount, 1) would
> > search column A.

>
> > If Cells(RowCount) = "Open" Then
> > If Cells(RowCount) = "Waiting" Then

>
> > "Jeff W." wrote:

>
> >> I want to create this sub or macro that will start at row 2 and cell A
> >> test for the a word and if this is found then select the cells on that
> >> row
> >> from A to H and change the format adding color to the cells based on
> >> the word found.

>
> >> This is what I have so far, but it doesnt work...

>
> >> It runs but it doesnt change anything, I'm lost, I'm not a vba programmer
> >> but this does make sence to me, sort of...

>
> >> Sub color_rows()
> >> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> >> For RowCount = 2 To lastrow
> >> a_num = RowCount 'row index
> >> h_num = RowCount + 7 'cell index

>
> >> If Cells(RowCount) = "Open" Then ' test for the word "Open"
> >> Cells("a_num:h_num").Select ' select cells A to H in the
> >> current row
> >> With Selection.Interior ' this would change the
> >> format of the selected cells
> >> .ColorIndex = 4
> >> .Pattern = xlSolid
> >> .PatternColorIndex = xlAutomatic
> >> End With
> >> End If

>
> >> If Cells(RowCount) = "Waiting" Then ' test for the word "Waiting"
> >> Cells("a_num:h_num").Select ' select cells A to H in
> >> the
> >> current row
> >> With Selection.Interior ' this would change
> >> the
> >> format of the selected cells
> >> .ColorIndex = 27
> >> .Pattern = xlSolid
> >> .PatternColorIndex = xlAutomatic
> >> End With
> >> End If

>
> >> If Cells(RowCount) = "Closed" Then ' test for the word "Closed"
> >> Cells("a_num:h_num").Select ' select cells A to H in
> >> the
> >> current row
> >> Selection.Interior.ColorIndex = xlNone ' this would change the color
> >> to
> >> none
> >> End If
> >> Next RowCount
> >> End Sub

>
> >> If anyone see's something wrong with this, I could sure use the help...

>
> >> Thanks,

>
> >> Jeff W.


Keep in mind, you don't have anything controlling if the cells are
already colored. Might want to clear the colorindex of the rows at
the top of the code to ensure that everything is formatted correctly.

Sub color_rows()
Dim lastrow As Long, rowcount As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For rowcount = 2 To lastrow
With Range(Cells(rowcount, 1), _
Cells(rowcount, 8)).Interior
If Cells(rowcount, 1).Value = _
"Open" Then
.ColorIndex = 4
ElseIf Cells(rowcount, 1) = _
"Waiting" Then
.ColorIndex = 27
ElseIf Cells(rowcount, 1) = _
"Closed" Then
.ColorIndex = xlNone
End If
End With
Next rowcount
End Sub

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      18th Oct 2007
On Oct 17, 9:35 pm, "Jeff W." <part_ma...@verizon.net> wrote:
> I made the change you suggested but now it wont run without
> Error it stops with "Type Mismatch" on the follwoing line;
>
> Cells("a_num:h_num").Select ' select cells A to H in the
>
> I have tried changing this to "Range" rather than "Cells" but the same error
>
> Any ideas?
>
> <Jeff>
>
> "JLGWhiz" <JLGW...@discussions.microsoft.com> wrote in message
>
> news:A0113FE9-7BC6-433C-83A3-(E-Mail Removed)...
>
> > These won't work becaus you are only referencing the row number. You need
> > to
> > include the column you want to search. expl: Cells(RowCount, 1) would
> > search column A.

>
> > If Cells(RowCount) = "Open" Then
> > If Cells(RowCount) = "Waiting" Then

>
> > "Jeff W." wrote:

>
> >> I want to create this sub or macro that will start at row 2 and cell A
> >> test for the a word and if this is found then select the cells on that
> >> row
> >> from A to H and change the format adding color to the cells based on
> >> the word found.

>
> >> This is what I have so far, but it doesnt work...

>
> >> It runs but it doesnt change anything, I'm lost, I'm not a vba programmer
> >> but this does make sence to me, sort of...

>
> >> Sub color_rows()
> >> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> >> For RowCount = 2 To lastrow
> >> a_num = RowCount 'row index
> >> h_num = RowCount + 7 'cell index

>
> >> If Cells(RowCount) = "Open" Then ' test for the word "Open"
> >> Cells("a_num:h_num").Select ' select cells A to H in the
> >> current row
> >> With Selection.Interior ' this would change the
> >> format of the selected cells
> >> .ColorIndex = 4
> >> .Pattern = xlSolid
> >> .PatternColorIndex = xlAutomatic
> >> End With
> >> End If

>
> >> If Cells(RowCount) = "Waiting" Then ' test for the word "Waiting"
> >> Cells("a_num:h_num").Select ' select cells A to H in
> >> the
> >> current row
> >> With Selection.Interior ' this would change
> >> the
> >> format of the selected cells
> >> .ColorIndex = 27
> >> .Pattern = xlSolid
> >> .PatternColorIndex = xlAutomatic
> >> End With
> >> End If

>
> >> If Cells(RowCount) = "Closed" Then ' test for the word "Closed"
> >> Cells("a_num:h_num").Select ' select cells A to H in
> >> the
> >> current row
> >> Selection.Interior.ColorIndex = xlNone ' this would change the color
> >> to
> >> none
> >> End If
> >> Next RowCount
> >> End Sub

>
> >> If anyone see's something wrong with this, I could sure use the help...

>
> >> Thanks,

>
> >> Jeff W.


Keep in mind, you don't have anything controlling if the cells are
already colored. Might want to clear the colorindex of the rows at
the top of the code to ensure that everything is formatted correctly.
Notice that there are no selections in the code. In general,
unnecessary selections is considered bad coding practice and should be
avoided if at all possible.

Sub color_rows()
Dim lastrow As Long, rowcount As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For rowcount = 2 To lastrow
With Range(Cells(rowcount, 1), _
Cells(rowcount, 8)).Interior
If Cells(rowcount, 1).Value = _
"Open" Then
.ColorIndex = 4
ElseIf Cells(rowcount, 1) = _
"Waiting" Then
.ColorIndex = 27
ElseIf Cells(rowcount, 1) = _
"Closed" Then
.ColorIndex = xlNone
End If
End With
Next rowcount
End Sub

 
Reply With Quote
 
Jeff W.
Guest
Posts: n/a
 
      18th Oct 2007
Works great!

The colors need to change based on the word changing so I dont
know if it can make any difference whether they are already colored.

I know from programming in other applications that there are usually
more than one way to get someing done, what you have done here is
certainly cleaner and more compact than my method.

Thanks...

Jeff W.



"JW" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Oct 17, 9:35 pm, "Jeff W." <part_ma...@verizon.net> wrote:
>> I made the change you suggested but now it wont run without
>> Error it stops with "Type Mismatch" on the follwoing line;
>>
>> Cells("a_num:h_num").Select ' select cells A to H in the
>>
>> I have tried changing this to "Range" rather than "Cells" but the same
>> error
>>
>> Any ideas?
>>
>> <Jeff>
>>
>> "JLGWhiz" <JLGW...@discussions.microsoft.com> wrote in message
>>
>> news:A0113FE9-7BC6-433C-83A3-(E-Mail Removed)...
>>
>> > These won't work becaus you are only referencing the row number. You
>> > need
>> > to
>> > include the column you want to search. expl: Cells(RowCount, 1) would
>> > search column A.

>>
>> > If Cells(RowCount) = "Open" Then
>> > If Cells(RowCount) = "Waiting" Then

>>
>> > "Jeff W." wrote:

>>
>> >> I want to create this sub or macro that will start at row 2 and cell A
>> >> test for the a word and if this is found then select the cells on that
>> >> row
>> >> from A to H and change the format adding color to the cells based on
>> >> the word found.

>>
>> >> This is what I have so far, but it doesnt work...

>>
>> >> It runs but it doesnt change anything, I'm lost, I'm not a vba
>> >> programmer
>> >> but this does make sence to me, sort of...

>>
>> >> Sub color_rows()
>> >> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
>> >> For RowCount = 2 To lastrow
>> >> a_num = RowCount 'row index
>> >> h_num = RowCount + 7 'cell index

>>
>> >> If Cells(RowCount) = "Open" Then ' test for the word "Open"
>> >> Cells("a_num:h_num").Select ' select cells A to H in the
>> >> current row
>> >> With Selection.Interior ' this would change
>> >> the
>> >> format of the selected cells
>> >> .ColorIndex = 4
>> >> .Pattern = xlSolid
>> >> .PatternColorIndex = xlAutomatic
>> >> End With
>> >> End If

>>
>> >> If Cells(RowCount) = "Waiting" Then ' test for the word "Waiting"
>> >> Cells("a_num:h_num").Select ' select cells A to H in
>> >> the
>> >> current row
>> >> With Selection.Interior ' this would
>> >> change
>> >> the
>> >> format of the selected cells
>> >> .ColorIndex = 27
>> >> .Pattern = xlSolid
>> >> .PatternColorIndex = xlAutomatic
>> >> End With
>> >> End If

>>
>> >> If Cells(RowCount) = "Closed" Then ' test for the word
>> >> "Closed"
>> >> Cells("a_num:h_num").Select ' select cells A to H
>> >> in
>> >> the
>> >> current row
>> >> Selection.Interior.ColorIndex = xlNone ' this would change the
>> >> color
>> >> to
>> >> none
>> >> End If
>> >> Next RowCount
>> >> End Sub

>>
>> >> If anyone see's something wrong with this, I could sure use the
>> >> help...

>>
>> >> Thanks,

>>
>> >> Jeff W.

>
> Keep in mind, you don't have anything controlling if the cells are
> already colored. Might want to clear the colorindex of the rows at
> the top of the code to ensure that everything is formatted correctly.
> Notice that there are no selections in the code. In general,
> unnecessary selections is considered bad coding practice and should be
> avoided if at all possible.
>
> Sub color_rows()
> Dim lastrow As Long, rowcount As Long
> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> For rowcount = 2 To lastrow
> With Range(Cells(rowcount, 1), _
> Cells(rowcount, 8)).Interior
> If Cells(rowcount, 1).Value = _
> "Open" Then
> .ColorIndex = 4
> ElseIf Cells(rowcount, 1) = _
> "Waiting" Then
> .ColorIndex = 27
> ElseIf Cells(rowcount, 1) = _
> "Closed" Then
> .ColorIndex = xlNone
> End If
> End With
> Next rowcount
> End Sub
>



 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      18th Oct 2007
You're welcome Jeff. I would still recommend clearing the cell color
index before the loop. What is a record that was previously "Open"
now has something like "Close" (Closed without the D). That row would
remain colored like the "Open" rows, but it truly isn't. Better safe
than sorry. To clear all color index values of all rows except the
header row, use something like below:
Sub clearColorIndex()
Rows("2:65536").Interior.ColorIndex = xlNone
'or Rows("2:" & Rows.Count).Interior.ColorIndex = xlNone
End Sub


Jeff W. wrote:
> Works great!
>
> The colors need to change based on the word changing so I dont
> know if it can make any difference whether they are already colored.
>
> I know from programming in other applications that there are usually
> more than one way to get someing done, what you have done here is
> certainly cleaner and more compact than my method.
>
> Thanks...
>
> Jeff W.
>
>
>
> "JW" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > On Oct 17, 9:35 pm, "Jeff W." <part_ma...@verizon.net> wrote:
> >> I made the change you suggested but now it wont run without
> >> Error it stops with "Type Mismatch" on the follwoing line;
> >>
> >> Cells("a_num:h_num").Select ' select cells A to H in the
> >>
> >> I have tried changing this to "Range" rather than "Cells" but the same
> >> error
> >>
> >> Any ideas?
> >>
> >> <Jeff>
> >>
> >> "JLGWhiz" <JLGW...@discussions.microsoft.com> wrote in message
> >>
> >> news:A0113FE9-7BC6-433C-83A3-(E-Mail Removed)...
> >>
> >> > These won't work becaus you are only referencing the row number. You
> >> > need
> >> > to
> >> > include the column you want to search. expl: Cells(RowCount, 1) would
> >> > search column A.
> >>
> >> > If Cells(RowCount) = "Open" Then
> >> > If Cells(RowCount) = "Waiting" Then
> >>
> >> > "Jeff W." wrote:
> >>
> >> >> I want to create this sub or macro that will start at row 2 and cell A
> >> >> test for the a word and if this is found then select the cells on that
> >> >> row
> >> >> from A to H and change the format adding color to the cells based on
> >> >> the word found.
> >>
> >> >> This is what I have so far, but it doesnt work...
> >>
> >> >> It runs but it doesnt change anything, I'm lost, I'm not a vba
> >> >> programmer
> >> >> but this does make sence to me, sort of...
> >>
> >> >> Sub color_rows()
> >> >> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> >> >> For RowCount = 2 To lastrow
> >> >> a_num = RowCount 'row index
> >> >> h_num = RowCount + 7 'cell index
> >>
> >> >> If Cells(RowCount) = "Open" Then ' test for the word "Open"
> >> >> Cells("a_num:h_num").Select ' select cells A to H in the
> >> >> current row
> >> >> With Selection.Interior ' this would change
> >> >> the
> >> >> format of the selected cells
> >> >> .ColorIndex = 4
> >> >> .Pattern = xlSolid
> >> >> .PatternColorIndex = xlAutomatic
> >> >> End With
> >> >> End If
> >>
> >> >> If Cells(RowCount) = "Waiting" Then ' test for the word "Waiting"
> >> >> Cells("a_num:h_num").Select ' select cells A to H in
> >> >> the
> >> >> current row
> >> >> With Selection.Interior ' this would
> >> >> change
> >> >> the
> >> >> format of the selected cells
> >> >> .ColorIndex = 27
> >> >> .Pattern = xlSolid
> >> >> .PatternColorIndex = xlAutomatic
> >> >> End With
> >> >> End If
> >>
> >> >> If Cells(RowCount) = "Closed" Then ' test for the word
> >> >> "Closed"
> >> >> Cells("a_num:h_num").Select ' select cells A to H
> >> >> in
> >> >> the
> >> >> current row
> >> >> Selection.Interior.ColorIndex = xlNone ' this would change the
> >> >> color
> >> >> to
> >> >> none
> >> >> End If
> >> >> Next RowCount
> >> >> End Sub
> >>
> >> >> If anyone see's something wrong with this, I could sure use the
> >> >> help...
> >>
> >> >> Thanks,
> >>
> >> >> Jeff W.

> >
> > Keep in mind, you don't have anything controlling if the cells are
> > already colored. Might want to clear the colorindex of the rows at
> > the top of the code to ensure that everything is formatted correctly.
> > Notice that there are no selections in the code. In general,
> > unnecessary selections is considered bad coding practice and should be
> > avoided if at all possible.
> >
> > Sub color_rows()
> > Dim lastrow As Long, rowcount As Long
> > lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> > For rowcount = 2 To lastrow
> > With Range(Cells(rowcount, 1), _
> > Cells(rowcount, 8)).Interior
> > If Cells(rowcount, 1).Value = _
> > "Open" Then
> > .ColorIndex = 4
> > ElseIf Cells(rowcount, 1) = _
> > "Waiting" Then
> > .ColorIndex = 27
> > ElseIf Cells(rowcount, 1) = _
> > "Closed" Then
> > .ColorIndex = xlNone
> > End If
> > End With
> > Next rowcount
> > End Sub
> >


 
Reply With Quote
 
Jeff W.
Guest
Posts: n/a
 
      18th Oct 2007
Thanks, I'll do that...

<Jeff>

"JW" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You're welcome Jeff. I would still recommend clearing the cell color
> index before the loop. What is a record that was previously "Open"
> now has something like "Close" (Closed without the D). That row would
> remain colored like the "Open" rows, but it truly isn't. Better safe
> than sorry. To clear all color index values of all rows except the
> header row, use something like below:
> Sub clearColorIndex()
> Rows("2:65536").Interior.ColorIndex = xlNone
> 'or Rows("2:" & Rows.Count).Interior.ColorIndex = xlNone
> End Sub
>
>
> Jeff W. wrote:
>> Works great!
>>
>> The colors need to change based on the word changing so I dont
>> know if it can make any difference whether they are already colored.
>>
>> I know from programming in other applications that there are usually
>> more than one way to get someing done, what you have done here is
>> certainly cleaner and more compact than my method.
>>
>> Thanks...
>>
>> Jeff W.
>>
>>
>>
>> "JW" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > On Oct 17, 9:35 pm, "Jeff W." <part_ma...@verizon.net> wrote:
>> >> I made the change you suggested but now it wont run without
>> >> Error it stops with "Type Mismatch" on the follwoing line;
>> >>
>> >> Cells("a_num:h_num").Select ' select cells A to H in the
>> >>
>> >> I have tried changing this to "Range" rather than "Cells" but the same
>> >> error
>> >>
>> >> Any ideas?
>> >>
>> >> <Jeff>
>> >>
>> >> "JLGWhiz" <JLGW...@discussions.microsoft.com> wrote in message
>> >>
>> >> news:A0113FE9-7BC6-433C-83A3-(E-Mail Removed)...
>> >>
>> >> > These won't work becaus you are only referencing the row number.
>> >> > You
>> >> > need
>> >> > to
>> >> > include the column you want to search. expl: Cells(RowCount, 1)
>> >> > would
>> >> > search column A.
>> >>
>> >> > If Cells(RowCount) = "Open" Then
>> >> > If Cells(RowCount) = "Waiting" Then
>> >>
>> >> > "Jeff W." wrote:
>> >>
>> >> >> I want to create this sub or macro that will start at row 2 and
>> >> >> cell A
>> >> >> test for the a word and if this is found then select the cells on
>> >> >> that
>> >> >> row
>> >> >> from A to H and change the format adding color to the cells based
>> >> >> on
>> >> >> the word found.
>> >>
>> >> >> This is what I have so far, but it doesnt work...
>> >>
>> >> >> It runs but it doesnt change anything, I'm lost, I'm not a vba
>> >> >> programmer
>> >> >> but this does make sence to me, sort of...
>> >>
>> >> >> Sub color_rows()
>> >> >> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
>> >> >> For RowCount = 2 To lastrow
>> >> >> a_num = RowCount 'row index
>> >> >> h_num = RowCount + 7 'cell index
>> >>
>> >> >> If Cells(RowCount) = "Open" Then ' test for the word "Open"
>> >> >> Cells("a_num:h_num").Select ' select cells A to H in
>> >> >> the
>> >> >> current row
>> >> >> With Selection.Interior ' this would change
>> >> >> the
>> >> >> format of the selected cells
>> >> >> .ColorIndex = 4
>> >> >> .Pattern = xlSolid
>> >> >> .PatternColorIndex = xlAutomatic
>> >> >> End With
>> >> >> End If
>> >>
>> >> >> If Cells(RowCount) = "Waiting" Then ' test for the word
>> >> >> "Waiting"
>> >> >> Cells("a_num:h_num").Select ' select cells A to H
>> >> >> in
>> >> >> the
>> >> >> current row
>> >> >> With Selection.Interior ' this would
>> >> >> change
>> >> >> the
>> >> >> format of the selected cells
>> >> >> .ColorIndex = 27
>> >> >> .Pattern = xlSolid
>> >> >> .PatternColorIndex = xlAutomatic
>> >> >> End With
>> >> >> End If
>> >>
>> >> >> If Cells(RowCount) = "Closed" Then ' test for the word
>> >> >> "Closed"
>> >> >> Cells("a_num:h_num").Select ' select cells A to
>> >> >> H
>> >> >> in
>> >> >> the
>> >> >> current row
>> >> >> Selection.Interior.ColorIndex = xlNone ' this would change the
>> >> >> color
>> >> >> to
>> >> >> none
>> >> >> End If
>> >> >> Next RowCount
>> >> >> End Sub
>> >>
>> >> >> If anyone see's something wrong with this, I could sure use the
>> >> >> help...
>> >>
>> >> >> Thanks,
>> >>
>> >> >> Jeff W.
>> >
>> > Keep in mind, you don't have anything controlling if the cells are
>> > already colored. Might want to clear the colorindex of the rows at
>> > the top of the code to ensure that everything is formatted correctly.
>> > Notice that there are no selections in the code. In general,
>> > unnecessary selections is considered bad coding practice and should be
>> > avoided if at all possible.
>> >
>> > Sub color_rows()
>> > Dim lastrow As Long, rowcount As Long
>> > lastrow = Cells(Rows.Count, "A").End(xlUp).Row
>> > For rowcount = 2 To lastrow
>> > With Range(Cells(rowcount, 1), _
>> > Cells(rowcount, 8)).Interior
>> > If Cells(rowcount, 1).Value = _
>> > "Open" Then
>> > .ColorIndex = 4
>> > ElseIf Cells(rowcount, 1) = _
>> > "Waiting" Then
>> > .ColorIndex = 27
>> > ElseIf Cells(rowcount, 1) = _
>> > "Closed" Then
>> > .ColorIndex = xlNone
>> > End If
>> > End With
>> > Next rowcount
>> > End Sub
>> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hiding rows based on cell contents =?Utf-8?B?SmFzb24gTQ==?= Microsoft Excel Misc 1 30th Oct 2006 04:30 PM
Add Rows based on Cell contents =?Utf-8?B?RG91ZyBNYW5uaW5n?= Microsoft Excel Misc 0 16th Sep 2005 07:01 PM
Coloring Cell Font based on Cell Contents willjohnson33@yahoo.com Microsoft Excel Programming 3 22nd Feb 2005 11:37 PM
hiding rows based on cell contents Bill Microsoft Excel Misc 1 14th Jan 2004 02:07 PM
Code to hide rows based on cell contents Tim Microsoft Excel Programming 5 17th Dec 2003 02:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:23 PM.