Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Problem with Code to Change Font Colour Q

I have the code below, given from this NS, which changes all negative
values to red font, but I'm getting a type mismatch error on line-
If c.Value < 0 Then

I've checked the sheet name spelling etc, but all looks ok

Sub ChangeFormatstoRed_whenNegative()

Application.ScreenUpdating = False
Sheets("Register").Activate
For Each c In ActiveSheet.UsedRange.Cells
If c.Value < 0 Then
c.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End If
Next
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Problem with Code to Change Font Colour Q

Maybe c.Value is an error cell, or something that fails when doing the
lessThan comparison

Not sure why you are testing each cell, simply decide the range you are
concerned with and do

dim rng as Range
set rng = Range("A1:B10")

rng.NumberFormat = "#,##0.00;[Red]-#,##0.00"

Regards,
Peter T


"Seanie" wrote in message
...
I have the code below, given from this NS, which changes all negative
values to red font, but I'm getting a type mismatch error on line-
If c.Value < 0 Then

I've checked the sheet name spelling etc, but all looks ok

Sub ChangeFormatstoRed_whenNegative()

Application.ScreenUpdating = False
Sheets("Register").Activate
For Each c In ActiveSheet.UsedRange.Cells
If c.Value < 0 Then
c.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End If
Next
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Problem with Code to Change Font Colour Q

On Nov 18, 12:05*pm, "Peter T" <peter_t@discussions wrote:
Maybe c.Value is an error cell, or something that fails when doing the
lessThan comparison

Not sure why you are testing each cell, simply decide the range you are
concerned with and do

dim rng as Range
set rng = Range("A1:B10")

rng.NumberFormat = "#,##0.00;[Red]-#,##0.00"

Regards,
Peter T

"Seanie" wrote in message

...



I have the code below, given from this NS, which changes all negative
values to red font, but I'm getting a type mismatch error on line-
If c.Value < 0 Then


I've checked the sheet name spelling etc, but all looks ok


Sub ChangeFormatstoRed_whenNegative()


Application.ScreenUpdating = False
Sheets("Register").Activate
* For Each c In ActiveSheet.UsedRange.Cells
* * If c.Value < 0 Then
* * * c.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
* * End If
* Next
End Sub- Hide quoted text -


- Show quoted text -


Thanks Peter, I can't see any obvious errors

Used your method, seems to work

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change font colour Min Excel Discussion (Misc queries) 9 February 18th 10 01:50 AM
Why isn't this code to change the font colour working? travis[_3_] Excel Programming 5 October 19th 08 06:58 AM
Change font colour Stefi Excel Discussion (Misc queries) 1 March 28th 07 01:54 AM
Change Font Colour in VB Q Sean Excel Programming 5 January 16th 07 02:31 AM
Change font colour Altec101[_8_] Excel Programming 15 May 30th 06 08:15 PM


All times are GMT +1. The time now is 05:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"