PC Review


Reply
Thread Tools Rate Thread

Cell colour doesn't delete

 
 
Sandy
Guest
Posts: n/a
 
      28th Jun 2007
I have the folloing code, why does the cell color in cell C10 not delete
when the value of cell C8 is ""?
Thanks Sandy

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Application.ScreenUpdating = False

Application.EnableEvents = False

For Each mycell In Range("C8:K8,M8:U8")
With mycell
If mycell.Value = "" Then
.Interior.ColorIndex = 36
.Font.ColorIndex = 1
.BorderAround LineStyle:=xlContinuous, Weight:=xlThin,
ColorIndex:=11
ElseIf mycell.Value <> "" Then
.Interior.ColorIndex = 11
.Font.ColorIndex = 45
.Borders.LineStyle = xlNone
End If
End With

With mycell.Offset(2)
If mycell.Value = 0 Then
.Interior.ColorIndex = 11
.Value = ""
ElseIf mycell.Value > 0 Then
.Interior.ColorIndex = 36
.Font.ColorIndex = 1
ElseIf mycell.Value = "" Then
.Interior.ColorIndex = xlColorIndexNone
.Value = ""
End If
End With
Next mycell

Application.ScreenUpdating = True

Application.EnableEvents = True

End Sub


 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      28th Jun 2007

If mycell.Value = 0 Then

ElseIf mycell.Value = "" Then

An empty cell equals both 0 and "" so in your code the test for empty
doesn't get processed.

In passing, I would suggest only change formats if they need changing,
particularly Font. Also test your target range for relevant changed cell(s)
and only process if need to.

Changing formats (except clear formats) does not trigger events so no need
to disable events.

Regards,
Peter T

"Sandy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have the folloing code, why does the cell color in cell C10 not delete
> when the value of cell C8 is ""?
> Thanks Sandy
>
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
>
> Application.ScreenUpdating = False
>
> Application.EnableEvents = False
>
> For Each mycell In Range("C8:K8,M8:U8")
> With mycell
> If mycell.Value = "" Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> .BorderAround LineStyle:=xlContinuous, Weight:=xlThin,
> ColorIndex:=11
> ElseIf mycell.Value <> "" Then
> .Interior.ColorIndex = 11
> .Font.ColorIndex = 45
> .Borders.LineStyle = xlNone
> End If
> End With
>
> With mycell.Offset(2)
> If mycell.Value = 0 Then
> .Interior.ColorIndex = 11
> .Value = ""
> ElseIf mycell.Value > 0 Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> ElseIf mycell.Value = "" Then
> .Interior.ColorIndex = xlColorIndexNone
> .Value = ""
> End If
> End With
> Next mycell
>
> Application.ScreenUpdating = True
>
> Application.EnableEvents = True
>
> End Sub
>
>



 
Reply With Quote
 
Edward
Guest
Posts: n/a
 
      28th Jun 2007
On Jun 28, 8:33 am, "Sandy" <sandy_step...@DELETEhotmail.com> wrote:
> I have the folloing code, why does the cell color in cell C10 not delete
> when the value of cell C8 is ""?
> Thanks Sandy
>
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
>
> Application.ScreenUpdating = False
>
> Application.EnableEvents = False
>
> For Each mycell In Range("C8:K8,M8:U8")
> With mycell
> If mycell.Value = "" Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> .BorderAround LineStyle:=xlContinuous, Weight:=xlThin,
> ColorIndex:=11
> ElseIf mycell.Value <> "" Then
> .Interior.ColorIndex = 11
> .Font.ColorIndex = 45
> .Borders.LineStyle = xlNone
> End If
> End With
>
> With mycell.Offset(2)
> If mycell.Value = 0 Then
> .Interior.ColorIndex = 11
> .Value = ""
> ElseIf mycell.Value > 0 Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> ElseIf mycell.Value = "" Then
> .Interior.ColorIndex = xlColorIndexNone
> .Value = ""
> End If
> End With
> Next mycell
>
> Application.ScreenUpdating = True
>
> Application.EnableEvents = True
>
> End Sub


What do you mean by cell color deleting? Your code changes the color
to 36 (a light yellow) and this works.

Edward

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      28th Jun 2007
Hi Sandy. You may also have problems deleting cell colors if the color was
set by conditional formatting. You have to include the FormatCondtions
property in your delete statement. See FormatConditions in VBA help.

"Sandy" wrote:

> I have the folloing code, why does the cell color in cell C10 not delete
> when the value of cell C8 is ""?
> Thanks Sandy
>
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
>
> Application.ScreenUpdating = False
>
> Application.EnableEvents = False
>
> For Each mycell In Range("C8:K8,M8:U8")
> With mycell
> If mycell.Value = "" Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> .BorderAround LineStyle:=xlContinuous, Weight:=xlThin,
> ColorIndex:=11
> ElseIf mycell.Value <> "" Then
> .Interior.ColorIndex = 11
> .Font.ColorIndex = 45
> .Borders.LineStyle = xlNone
> End If
> End With
>
> With mycell.Offset(2)
> If mycell.Value = 0 Then
> .Interior.ColorIndex = 11
> .Value = ""
> ElseIf mycell.Value > 0 Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> ElseIf mycell.Value = "" Then
> .Interior.ColorIndex = xlColorIndexNone
> .Value = ""
> End If
> End With
> Next mycell
>
> Application.ScreenUpdating = True
>
> Application.EnableEvents = True
>
> End Sub
>
>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      28th Jun 2007
"" & 0 are the same, try

If Len(Trim(mycell)) > 0 Then

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"Sandy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have the folloing code, why does the cell color in cell C10 not delete
>when the value of cell C8 is ""?
> Thanks Sandy
>
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
>
> Application.ScreenUpdating = False
>
> Application.EnableEvents = False
>
> For Each mycell In Range("C8:K8,M8:U8")
> With mycell
> If mycell.Value = "" Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> .BorderAround LineStyle:=xlContinuous, Weight:=xlThin,
> ColorIndex:=11
> ElseIf mycell.Value <> "" Then
> .Interior.ColorIndex = 11
> .Font.ColorIndex = 45
> .Borders.LineStyle = xlNone
> End If
> End With
>
> With mycell.Offset(2)
> If mycell.Value = 0 Then
> .Interior.ColorIndex = 11
> .Value = ""
> ElseIf mycell.Value > 0 Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> ElseIf mycell.Value = "" Then
> .Interior.ColorIndex = xlColorIndexNone
> .Value = ""
> End If
> End With
> Next mycell
>
> Application.ScreenUpdating = True
>
> Application.EnableEvents = True
>
> End Sub
>


 
Reply With Quote
 
Sandy
Guest
Posts: n/a
 
      28th Jun 2007
Thanks all, Don's suggestion is good for what I want.
Sandy

"Sandy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have the folloing code, why does the cell color in cell C10 not delete
>when the value of cell C8 is ""?
> Thanks Sandy
>
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
>
> Application.ScreenUpdating = False
>
> Application.EnableEvents = False
>
> For Each mycell In Range("C8:K8,M8:U8")
> With mycell
> If mycell.Value = "" Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> .BorderAround LineStyle:=xlContinuous, Weight:=xlThin,
> ColorIndex:=11
> ElseIf mycell.Value <> "" Then
> .Interior.ColorIndex = 11
> .Font.ColorIndex = 45
> .Borders.LineStyle = xlNone
> End If
> End With
>
> With mycell.Offset(2)
> If mycell.Value = 0 Then
> .Interior.ColorIndex = 11
> .Value = ""
> ElseIf mycell.Value > 0 Then
> .Interior.ColorIndex = 36
> .Font.ColorIndex = 1
> ElseIf mycell.Value = "" Then
> .Interior.ColorIndex = xlColorIndexNone
> .Value = ""
> End If
> End With
> Next mycell
>
> Application.ScreenUpdating = True
>
> Application.EnableEvents = True
>
> End Sub
>



 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      28th Jun 2007
Glad to help

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"Sandy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks all, Don's suggestion is good for what I want.
> Sandy
>
> "Sandy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I have the folloing code, why does the cell color in cell C10 not delete
>>when the value of cell C8 is ""?
>> Thanks Sandy
>>
>> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
>>
>> Application.ScreenUpdating = False
>>
>> Application.EnableEvents = False
>>
>> For Each mycell In Range("C8:K8,M8:U8")
>> With mycell
>> If mycell.Value = "" Then
>> .Interior.ColorIndex = 36
>> .Font.ColorIndex = 1
>> .BorderAround LineStyle:=xlContinuous, Weight:=xlThin,
>> ColorIndex:=11
>> ElseIf mycell.Value <> "" Then
>> .Interior.ColorIndex = 11
>> .Font.ColorIndex = 45
>> .Borders.LineStyle = xlNone
>> End If
>> End With
>>
>> With mycell.Offset(2)
>> If mycell.Value = 0 Then
>> .Interior.ColorIndex = 11
>> .Value = ""
>> ElseIf mycell.Value > 0 Then
>> .Interior.ColorIndex = 36
>> .Font.ColorIndex = 1
>> ElseIf mycell.Value = "" Then
>> .Interior.ColorIndex = xlColorIndexNone
>> .Value = ""
>> End If
>> End With
>> Next mycell
>>
>> Application.ScreenUpdating = True
>>
>> Application.EnableEvents = 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
Delete an entire row if a selected row doesn't have a specified value in a cell marcusdmc@gmail.com Microsoft Excel Programming 1 27th Jun 2007 09:06 PM
xl 2000 - changing chart colour doesn't update legend colour insert your name here Microsoft Excel Discussion 2 10th Sep 2006 09:25 AM
Delete row data and cell colour alex1982 Microsoft Excel Programming 6 21st Aug 2006 03:57 PM
delete cell that doesn't contain a specific word luke.robert.terry@gmail.com Microsoft Excel Misc 1 12th Oct 2005 05:54 AM
background colour of a cell doesn't appear on print Carl Windows XP Internet Explorer 1 5th Mar 2004 05:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:06 PM.