Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change cell colour for a cell or range within a predefined range

Dear all,

The code below is working to change the cell colour in one cell only within
range(C4:C12). A message box appears when the user tries outside the range.

Is it possible to change the code to enable change of a range of cells and
also lets say C5 and C8 at the same time - within the range(C4:C12). The
message box should appear when trying to change colour in lets say
range(C6:C15).

Sub White()

If Not Intersect(ActiveCell, [C4:C12]) Is Nothing Then
ActiveCell.Interior.ColorIndex = 0
Else
MsgBox "It is only possible to change colour in C4 down to C12 "
& vbNewLine & "in Column C only!", vbCritical, "Cell Colour Change"
End If

End Sub

--
Regards,

Martin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Change cell colour for a cell or range within a predefined range

Yes, you can use the Selection object to refer to the selected cells, even if
not a continuous range, and then step through the individual cells with a For
Each... loop:

Sub White()
Dim ThisCell as Range, Oops as Boolean

For Each ThisCell in Selection.Cells
If Not Intersect(ThisCell, [C4:C12]) Is Nothing Then
ThisCell.Interior.ColorIndex = 0
Else
Oops = True
End If
Next ThisCell

If Oops Then MsgBox "It is only possible to change colour in C4 down to C12
" & vbNewLine & "in Column C only!", vbCritical, "Cell Colour Change"


"Martin" wrote:

Dear all,

The code below is working to change the cell colour in one cell only within
range(C4:C12). A message box appears when the user tries outside the range.

Is it possible to change the code to enable change of a range of cells and
also lets say C5 and C8 at the same time - within the range(C4:C12). The
message box should appear when trying to change colour in lets say
range(C6:C15).

Sub White()

If Not Intersect(ActiveCell, [C4:C12]) Is Nothing Then
ActiveCell.Interior.ColorIndex = 0
Else
MsgBox "It is only possible to change colour in C4 down to C12 "
& vbNewLine & "in Column C only!", vbCritical, "Cell Colour Change"
End If

End Sub

--
Regards,

Martin

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change cell colour for a cell or range within a predefined ran

That's great - thank you very much!
--
Regards,

Martin


"K Dales" wrote:

Yes, you can use the Selection object to refer to the selected cells, even if
not a continuous range, and then step through the individual cells with a For
Each... loop:

Sub White()
Dim ThisCell as Range, Oops as Boolean

For Each ThisCell in Selection.Cells
If Not Intersect(ThisCell, [C4:C12]) Is Nothing Then
ThisCell.Interior.ColorIndex = 0
Else
Oops = True
End If
Next ThisCell

If Oops Then MsgBox "It is only possible to change colour in C4 down to C12
" & vbNewLine & "in Column C only!", vbCritical, "Cell Colour Change"


"Martin" wrote:

Dear all,

The code below is working to change the cell colour in one cell only within
range(C4:C12). A message box appears when the user tries outside the range.

Is it possible to change the code to enable change of a range of cells and
also lets say C5 and C8 at the same time - within the range(C4:C12). The
message box should appear when trying to change colour in lets say
range(C6:C15).

Sub White()

If Not Intersect(ActiveCell, [C4:C12]) Is Nothing Then
ActiveCell.Interior.ColorIndex = 0
Else
MsgBox "It is only possible to change colour in C4 down to C12 "
& vbNewLine & "in Column C only!", vbCritical, "Cell Colour Change"
End If

End Sub

--
Regards,

Martin

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
How to count specific colour from cell range with varied colors? nick Excel Worksheet Functions 1 April 16th 07 12:27 PM
Count filled colour in cell in given range [email protected] Excel Discussion (Misc queries) 2 May 16th 06 10:18 AM
Conditional Format - Formula to Colour Every 3rd Cell in Offset Range Sam via OfficeKB.com Excel Discussion (Misc queries) 7 August 13th 05 04:19 AM
Change even rows to a predefined colour Pat Excel Programming 4 March 16th 05 01:16 AM
Range.Find returns cell outside of range when range set to single cell Frank Jones Excel Programming 12 June 10th 04 04:22 AM


All times are GMT +1. The time now is 07:50 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"