PC Review


Reply
Thread Tools Rate Thread

code to change font color of row

 
 
Mark Kubicki
Guest
Posts: n/a
 
      29th Dec 2008
I've got this code written to change the font color of a row based on the
value entered into column A of that row, but the color does not change

this code fires from within the worksheet -like an extended conditional
format
interesting note... I have a similar code written to update the color of all
the rows on the worksheet when the workbook itself opens, and that code
works fine

any suggestions would be greatly appreciated,
thanks in advance,
mark


Private Sub Worksheet_Change(ByVal target As Range)
Call UpdateRowColor(target)
End Sub

Sub UpdateRowColor(target As Range)
Dim response As Boolean
Dim vPhase As String
Application.ScreenUpdating = False
If Not Intersect(target, Range("A:A")) Is Nothing Then
If target.Count > 1 Then
response = MsgBox("Please select only 1 row at a time; (color
will not update otherwise)", vbOKOnly, "MULTILE ROWS SELECTED")
Exit Sub
Else
vPhase = UCase(Trim(Range("A" & target.Row).Value))
Select Case vPhase
Case Is = "CA"
Rows(target.Row & ":" &
target.Row).Font.ColorIndex = 45
Case Is = ...
End Select
End If
End If
Application.ScreenUpdating = True
End sub


 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      30th Dec 2008
Your code is causing a infinite loop! When you change the entire row you
are re-triggering the event!

Disable events before updating and re-enable after. You are also exiting the
loop (Exit Sub) before restoring screen updating, try changing the code as
follows....

Sub UpdateRowColor(target As Range)
Dim response As Boolean
Dim vPhase As String
Application.ScreenUpdating = False
Application.EnableEvents = False
If Not Intersect(target, Range("A:A")) Is Nothing Then
If target.Count = 1 Then
vPhase = UCase(Trim(Range("A" & target.Row).Value))
Select Case vPhase
Case Is = "CA"
Rows(target.Row & ":" &
target.Row).Font.ColorIndex = 45
'Case Is = ...
End Select
Else
MsgBox "Please select only 1 row at a time; (color will not update
otherwise)", vbOKOnly, "MULTIPLE ROWS SELECTED"
End If
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

--

Regards,
Nigel
(E-Mail Removed)



"Mark Kubicki" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I've got this code written to change the font color of a row based on the
> value entered into column A of that row, but the color does not change
>
> this code fires from within the worksheet -like an extended conditional
> format
> interesting note... I have a similar code written to update the color of
> all the rows on the worksheet when the workbook itself opens, and that
> code works fine
>
> any suggestions would be greatly appreciated,
> thanks in advance,
> mark
>
>
> Private Sub Worksheet_Change(ByVal target As Range)
> Call UpdateRowColor(target)
> End Sub
>
> Sub UpdateRowColor(target As Range)
> Dim response As Boolean
> Dim vPhase As String
> Application.ScreenUpdating = False
> If Not Intersect(target, Range("A:A")) Is Nothing Then
> If target.Count > 1 Then
> response = MsgBox("Please select only 1 row at a time; (color
> will not update otherwise)", vbOKOnly, "MULTILE ROWS SELECTED")
> Exit Sub
> Else
> vPhase = UCase(Trim(Range("A" & target.Row).Value))
> Select Case vPhase
> Case Is = "CA"
> Rows(target.Row & ":" &
> target.Row).Font.ColorIndex = 45
> Case Is = ...
> End Select
> End If
> End If
> Application.ScreenUpdating = True
> 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
Modify code from paste values to change font color / multiple rang Nina Microsoft Excel Programming 3 9th Mar 2010 08:36 PM
Checkbox to change background color, font color and remove/ add bo Sara Microsoft Excel Misc 1 11th Nov 2008 08:17 PM
How to change the default Border, Font Color, and Cell Color Elijah Microsoft Excel Misc 3 2nd Nov 2005 11:52 PM
Bullet Font Color Changes When I Change Text Color--Can I Change it Back? J. Danniel Microsoft Powerpoint 2 17th Mar 2005 08:06 PM
Change the font and font color for the desktop folder names Greg Campanella Windows XP Customization 0 26th Nov 2003 07:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 PM.