Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Naz Naz is offline
external usenet poster
 
Posts: 85
Default conditional format macro not working - almost there

Hi

I'm trying to do a macro to conditionally format some cells depending on
there value
this is the code i have written, but it only works if the whole range is a
certain number and not on the individual cells within the range.

Private Sub Worksheet_Change(ByVal Target As Range)

' This macro is activated everytime a change is made to this worksheet
(TestArea)


Dim r As Range

'Set the range for the formatting
Set r = Intersect(Range("Ranges1"), Target)

'If the change in the worksheet is not in the tested range, exit the macro.
If r Is Nothing Then Exit Sub

'Change to formatting of the cell that changed.
For Each cell In Range("Ranges1")

Select Case cell
Case 1
Selection.Interior.ColorIndex = 2
Case 2, 3
Selection.Interior.ColorIndex = 4
Case 4 To 6
Selection.Interior.ColorIndex = 6
Case Is 8
Selection.Interior.ColorIndex = 8
Case Else
Selection.Interior.ColorIndex = 10
End Select


Next

End Sub

All help is appreciated

--

_______________________
Naz,
London
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default conditional format macro not working - almost there

Hi Naz,

Try this modification of your code:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)
' This macro is activated everytime a change is made to
' this worksheet (TestArea)
Dim r As Range
Dim cell As Range

'Set the range for the formatting
Set r = Intersect(Range("Ranges1"), Target)

' If the change in the worksheet is not in the
' tested range, exit the macro.
If r Is Nothing Then Exit Sub

'Change to formatting of the cell that changed.
For Each cell In Range("Ranges1")
With cell
Select Case cell
Case 1
.Interior.ColorIndex = 2
Case 2, 3
.Interior.ColorIndex = 4
Case 4 To 6
.Interior.ColorIndex = 6
Case Is 8
.Interior.ColorIndex = 8
Case Else
.Interior.ColorIndex = 10
End Select

End With
Next
End Sub
'<<=============


---
Regards,
Norman



"Naz" wrote in message
...
Hi

I'm trying to do a macro to conditionally format some cells depending on
there value
this is the code i have written, but it only works if the whole range is a
certain number and not on the individual cells within the range.

Private Sub Worksheet_Change(ByVal Target As Range)

' This macro is activated everytime a change is made to this worksheet
(TestArea)


Dim r As Range

'Set the range for the formatting
Set r = Intersect(Range("Ranges1"), Target)

'If the change in the worksheet is not in the tested range, exit the
macro.
If r Is Nothing Then Exit Sub

'Change to formatting of the cell that changed.
For Each cell In Range("Ranges1")

Select Case cell
Case 1
Selection.Interior.ColorIndex = 2
Case 2, 3
Selection.Interior.ColorIndex = 4
Case 4 To 6
Selection.Interior.ColorIndex = 6
Case Is 8
Selection.Interior.ColorIndex = 8
Case Else
Selection.Interior.ColorIndex = 10
End Select


Next

End Sub

All help is appreciated

--

_______________________
Naz,
London



  #3   Report Post  
Posted to microsoft.public.excel.programming
JR JR is offline
external usenet poster
 
Posts: 92
Default conditional format macro not working - almost there

....don't re-invent the wheel. Just conditionally format the cells based on
the given criteria and leave the macro out.

"Naz" wrote:

Hi

I'm trying to do a macro to conditionally format some cells depending on
there value
this is the code i have written, but it only works if the whole range is a
certain number and not on the individual cells within the range.

Private Sub Worksheet_Change(ByVal Target As Range)

' This macro is activated everytime a change is made to this worksheet
(TestArea)


Dim r As Range

'Set the range for the formatting
Set r = Intersect(Range("Ranges1"), Target)

'If the change in the worksheet is not in the tested range, exit the macro.
If r Is Nothing Then Exit Sub

'Change to formatting of the cell that changed.
For Each cell In Range("Ranges1")

Select Case cell
Case 1
Selection.Interior.ColorIndex = 2
Case 2, 3
Selection.Interior.ColorIndex = 4
Case 4 To 6
Selection.Interior.ColorIndex = 6
Case Is 8
Selection.Interior.ColorIndex = 8
Case Else
Selection.Interior.ColorIndex = 10
End Select


Next

End Sub

All help is appreciated

--

_______________________
Naz,
London

  #4   Report Post  
Posted to microsoft.public.excel.programming
Naz Naz is offline
external usenet poster
 
Posts: 85
Default conditional format macro not working - almost there

Not trying to re-invent the wheel, i'm going to need to use this code with
upto 20 conditions which the normal conditional format won't be able to do,
as its limited to only 4 (incl default) conditions.
--

_______________________
Naz,
London


"JR" wrote:

...don't re-invent the wheel. Just conditionally format the cells based on
the given criteria and leave the macro out.

"Naz" wrote:

Hi

I'm trying to do a macro to conditionally format some cells depending on
there value
this is the code i have written, but it only works if the whole range is a
certain number and not on the individual cells within the range.

Private Sub Worksheet_Change(ByVal Target As Range)

' This macro is activated everytime a change is made to this worksheet
(TestArea)


Dim r As Range

'Set the range for the formatting
Set r = Intersect(Range("Ranges1"), Target)

'If the change in the worksheet is not in the tested range, exit the macro.
If r Is Nothing Then Exit Sub

'Change to formatting of the cell that changed.
For Each cell In Range("Ranges1")

Select Case cell
Case 1
Selection.Interior.ColorIndex = 2
Case 2, 3
Selection.Interior.ColorIndex = 4
Case 4 To 6
Selection.Interior.ColorIndex = 6
Case Is 8
Selection.Interior.ColorIndex = 8
Case Else
Selection.Interior.ColorIndex = 10
End Select


Next

End Sub

All help is appreciated

--

_______________________
Naz,
London

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
Conditional Format Not Working sly411 Excel Discussion (Misc queries) 0 May 20th 10 02:08 PM
Conditional Format Not Working roxiemayfield Excel Worksheet Functions 4 December 6th 07 07:42 PM
Conditional Formatting Not Working In Macro Dave Excel Discussion (Misc queries) 3 October 5th 07 01:49 PM
Conditional Format as a MACRO Gunjani Excel Worksheet Functions 3 March 29th 06 05:22 PM
Conditional Format Not Working KMH Excel Discussion (Misc queries) 0 December 22nd 05 05:32 PM


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