PC Review


Reply
Thread Tools Rate Thread

Change Font Color for Dupes on Selection Change

 
 
MiataDiablo@gmail.com
Guest
Posts: n/a
 
      6th Sep 2008
For various reasons, I would prefer to use vba as opposed to
conditional formatting for my worksheet. If a duplicate value (in
this case, lengthy text entries) exists, change the font color to
blue. I can successfully write the macro for it but again, I would
prefer that it fire automatically on the Worksheet Selection Change
and I just can't figure how to make that work.

"=COUNTIF($D$1:$D$1000,D1)>1"

Any assistance greatly appreciated as always.
 
Reply With Quote
 
 
 
 
JMay
Guest
Posts: n/a
 
      6th Sep 2008
How about:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 4 Then Exit Sub
If Application.WorksheetFunction.CountIf(Range("$D$1:$D$1000"), Target) > 1
Then
Target.Interior.ColorIndex = 6
End If
End Sub

"(E-Mail Removed)" wrote:

> For various reasons, I would prefer to use vba as opposed to
> conditional formatting for my worksheet. If a duplicate value (in
> this case, lengthy text entries) exists, change the font color to
> blue. I can successfully write the macro for it but again, I would
> prefer that it fire automatically on the Worksheet Selection Change
> and I just can't figure how to make that work.
>
> "=COUNTIF($D$1:$D$1000,D1)>1"
>
> Any assistance greatly appreciated as always.
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      6th Sep 2008
Try something like

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then ' In XL2007, use CountLarge, not Count
Exit Sub
End If
If Target.Text = vbNullString Then
Target.Font.ColorIndex = xlColorIndexAutomatic
Exit Sub
End If
If Application.WorksheetFunction.CountIf( _
Me.Range("A1:A100"), Target.Text) > 1 Then
Target.Font.ColorIndex = 3 ' red
Else
Target.Font.ColorIndex = xlColorIndexAutomatic
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




<(E-Mail Removed)> wrote in message
news:7effc494-ffd3-4a44-8907-(E-Mail Removed)...
> For various reasons, I would prefer to use vba as opposed to
> conditional formatting for my worksheet. If a duplicate value (in
> this case, lengthy text entries) exists, change the font color to
> blue. I can successfully write the macro for it but again, I would
> prefer that it fire automatically on the Worksheet Selection Change
> and I just can't figure how to make that work.
>
> "=COUNTIF($D$1:$D$1000,D1)>1"
>
> Any assistance greatly appreciated as always.


 
Reply With Quote
 
MiataDiablo@gmail.com
Guest
Posts: n/a
 
      7th Sep 2008
On Sep 6, 9:00*am, "Chip Pearson" <c...@cpearson.com> wrote:
> Try something like
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> * * If Target.Cells.Count > 1 Then ' In XL2007, use CountLarge, not Count
> * * * * Exit Sub
> * * End If
> * * If Target.Text = vbNullString Then
> * * * * Target.Font.ColorIndex = xlColorIndexAutomatic
> * * * * Exit Sub
> * * End If
> * * If Application.WorksheetFunction.CountIf( _
> * * * * * * * * Me.Range("A1:A100"), Target.Text) > 1 Then
> * * * * Target.Font.ColorIndex = 3 ' red
> * * Else
> * * * * Target.Font.ColorIndex = xlColorIndexAutomatic
> * * End If
> End Sub
>
> --
> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional
> * *ExcelProduct Group
> Pearson Software Consulting, LLCwww.cpearson.com
> (email on web site)
>
> <MiataDia...@gmail.com> wrote in message
>
> news:7effc494-ffd3-4a44-8907-(E-Mail Removed)...
>
>
>
> > For various reasons, I would prefer to use vba as opposed to
> > conditional formatting for my worksheet. *If a duplicate value (in
> > this case, lengthy text entries) exists, change the font color to
> > blue. *I can successfully write the macro for it but again, I would
> > prefer that it fire automatically on the Worksheet Selection Change
> > and I just can't figure how to make that work.

>
> > "=COUNTIF($D$1:$D$1000,D1)>1"

>
> > Any assistance greatly appreciated as always.- Hide quoted text -

>
> - Show quoted text -


It seems so easy once someone gives you the answer. Hah! Thanks a
million to both of you
 
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
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
How do I get the font color to change according to the selection . =?Utf-8?B?R3JlZw==?= Microsoft Excel Misc 7 13th Oct 2004 07:45 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 11:32 PM.