Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cell Colour based on text in Range of cells


Hi!

I'm not too familiar with VBA, so i was hoping someone could please
help me!

I want to change the background colour of a single cell, based on the
text in a range of cells (which can be one of two options.) I want the
cell colour of F14 to change if *all* the cells in G14:S14 contain
either "N/A" or a date timestamp. This is what i tried out:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim icolor As Integer


If Not Intersect(Target, Range("G14:S14")) Is Nothing Then
If Range("G14:S14").Text = "N/A" Or "date value" Then

Range("F14").Interior.ColorIndex = 4
Else
Range("F14").Interior.ColorIndex = 0
End If
End If

End Sub

This pretty much does the job, but the Or condition doesnt work. Any
help would be much appreciated!! Thanks!!


--
viewmaster
------------------------------------------------------------------------
viewmaster's Profile: http://www.excelforum.com/member.php...o&userid=32094
View this thread: http://www.excelforum.com/showthread...hreadid=518485

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Cell Colour based on text in Range of cells

Private Sub Worksheet_Change(ByVal Target As Range)
Dim bOk as Boolean, cell as Range
Dim icolor As Integer
If Not Intersect(Target, Range("G14:S14")) Is Nothing Then
bOk = True

for each cell in Range("G14:S14")
if not isdate(cell.Value) then
if cell.Text < "N/A" then
bOK = False
exit for
end if
end if
Next
If bOk then
Range("F14").Interior.ColorIndex = 4
Else
Range("F14").Interior.ColorIndex = 0
End If
End if

End Sub

--
Regards,
Tom Ogilvy

"viewmaster" wrote
in message ...

Hi!

I'm not too familiar with VBA, so i was hoping someone could please
help me!

I want to change the background colour of a single cell, based on the
text in a range of cells (which can be one of two options.) I want the
cell colour of F14 to change if *all* the cells in G14:S14 contain
either "N/A" or a date timestamp. This is what i tried out:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim icolor As Integer


If Not Intersect(Target, Range("G14:S14")) Is Nothing Then
If Range("G14:S14").Text = "N/A" Or "date value" Then

Range("F14").Interior.ColorIndex = 4
Else
Range("F14").Interior.ColorIndex = 0
End If
End If

End Sub

This pretty much does the job, but the Or condition doesnt work. Any
help would be much appreciated!! Thanks!!


--
viewmaster
------------------------------------------------------------------------
viewmaster's Profile:

http://www.excelforum.com/member.php...o&userid=32094
View this thread: http://www.excelforum.com/showthread...hreadid=518485



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cell Colour based on text in Range of cells


Thank you soooo much! It works a charm!

--
viewmaste
-----------------------------------------------------------------------
viewmaster's Profile: http://www.excelforum.com/member.php...fo&userid=3209
View this thread: http://www.excelforum.com/showthread.php?threadid=51848

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
Cell Colour based on text in Range of cells viewmaster Excel Programming 1 March 3rd 06 03:42 AM
get range of cells based on colour skellis Excel Programming 1 September 22nd 05 07:01 AM
How do I set a colour to 4 cells based on the value of a cell Andy64 Excel Discussion (Misc queries) 1 September 6th 05 06:46 PM
Adding colour to a range of cells based on one of the cells v... McKenna Excel Discussion (Misc queries) 4 March 11th 05 02:25 PM
Change the colour of a bunch of cells, based on one cell. Craig & Co. Excel Programming 2 October 14th 04 06:28 AM


All times are GMT +1. The time now is 05:20 PM.

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

About Us

"It's about Microsoft Excel"