Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Using VBA: Extending limits of Conditional Formatting

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Using VBA: Extending limits of Conditional Formatting

You can have as many as you want with this. It;s worksheet code so
right-click the tab, view code and paste in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim CellVal As String
If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("A1:c100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Select Case CellVal
Case "Dog"
Target.Interior.ColorIndex = 5
Case "Cat"
Target.Interior.ColorIndex = 10
Case "Other"
Target.Interior.ColorIndex = 6
Case "Rabbit"
Target.Interior.ColorIndex = 46
Case "Goat"
Target.Interior.ColorIndex = 45
End Select
End If
End Sub

Mike

"Art Caragh" wrote:

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Using VBA: Extending limits of Conditional Formatting

You can use arbitrary conditions in VBA:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Range("B9"), Target) Is Nothing Then
Exit Sub
End If
v = Target.Value
clrs = Array("red", "blue", "green", "yellow")
cds = Array(3, 5, 10, 6)
For i = 0 To 3
If v = clrs(i) Then
Application.EnableEvents = False
Target.Interior.ColorIndex = cds(i)
Application.EnableEvents = True
End If
Next
End Sub

This worksheet code looks for changes in cell B9. If the contents become
"red", "blue", "green", or "yellow" then the background color changes.
--
Gary''s Student - gsnu200724


"Art Caragh" wrote:

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Using VBA: Extending limits of Conditional Formatting

Thankyou Mike

It works like a dream

"Mike H" wrote:

You can have as many as you want with this. It;s worksheet code so
right-click the tab, view code and paste in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim CellVal As String
If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("A1:c100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Select Case CellVal
Case "Dog"
Target.Interior.ColorIndex = 5
Case "Cat"
Target.Interior.ColorIndex = 10
Case "Other"
Target.Interior.ColorIndex = 6
Case "Rabbit"
Target.Interior.ColorIndex = 46
Case "Goat"
Target.Interior.ColorIndex = 45
End Select
End If
End Sub

Mike

"Art Caragh" wrote:

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using VBA: Extending limits of Conditional Formatting


Hi Mike I'm having a simular problem but I need an entire Row to change
color to change as a result of the value of one cell is there way to do
this using this VBA?



*** Sent via Developersdex http://www.developersdex.com ***


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Using VBA: Extending limits of Conditional Formatting

One way:

In Mike's code, instead of

Target.Interior.ColorIndex = x

use

Target.EntireRow.Interior.ColorIndex = x



In article ,
Chris Pederson wrote:

Hi Mike I'm having a simular problem but I need an entire Row to change
color to change as a result of the value of one cell is there way to do
this using this VBA?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Using VBA: Extending limits of Conditional Formatting

When I delete the value in a cell the color doesn't revert to white.

"Mike H" wrote:

You can have as many as you want with this. It;s worksheet code so
right-click the tab, view code and paste in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim CellVal As String
If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("A1:c100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Select Case CellVal
Case "Dog"
Target.Interior.ColorIndex = 5
Case "Cat"
Target.Interior.ColorIndex = 10
Case "Other"
Target.Interior.ColorIndex = 6
Case "Rabbit"
Target.Interior.ColorIndex = 46
Case "Goat"
Target.Interior.ColorIndex = 45
End Select
End If
End Sub

Mike

"Art Caragh" wrote:

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using VBA: Extending limits of Conditional Formatting

being an absolute beginner at VBA, i'm floundering in ever deeper waters, ive
created a employee leave worksheet, which is along the lines that it requires
more colours than allowed by excel, the code is a god send, but this is the
only VBA code that is on the worksheet.
How can i run this piece of code? as when itry to run it it asks for a macro
which i have tried to look up and learn using the excel help.

"Mike H" wrote:

You can have as many as you want with this. It;s worksheet code so
right-click the tab, view code and paste in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim CellVal As String
If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("A1:c100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Select Case CellVal
Case "Dog"
Target.Interior.ColorIndex = 5
Case "Cat"
Target.Interior.ColorIndex = 10
Case "Other"
Target.Interior.ColorIndex = 6
Case "Rabbit"
Target.Interior.ColorIndex = 46
Case "Goat"
Target.Interior.ColorIndex = 45
End Select
End If
End Sub

Mike

"Art Caragh" wrote:

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Using VBA: Extending limits of Conditional Formatting

Dave,

You cannot run this macro since it is code for an Excel event, which means that Excel runs the code
when something specific happens - in this case, a change is made to a cell on the sheet.

If you want to run the code as a macro, the code will need to be modified to run from a regular
codemodule. For example, select the cells that you want to have formatted, and run code like this.

Sub ApplyFormats()
Dim WatchRange As Range
Dim myC As Range
Set WatchRange = Range("A1:C100") 'change to suit
For Each myC In WatchRange
If Not IsError(Application.VLookup(myC.Value, Range("ColorTable"), 2, False)) Then
myC.Interior.ColorIndex = Application.VLookup(myC.Value, Range("ColorTable"), 2, False)
End If
Next myC
End Sub

For this code to work, you need to create a named range ColorTable, where the range includes your
values and color indexes:

Dog 5
Cat 10
Other 6
Rabbit 46
Goat 45

HTH,
Bernie
MS Excel MVP


"Dave ferret" <Dave wrote in message
...
being an absolute beginner at VBA, i'm floundering in ever deeper waters, ive
created a employee leave worksheet, which is along the lines that it requires
more colours than allowed by excel, the code is a god send, but this is the
only VBA code that is on the worksheet.
How can i run this piece of code? as when itry to run it it asks for a macro
which i have tried to look up and learn using the excel help.

"Mike H" wrote:

You can have as many as you want with this. It;s worksheet code so
right-click the tab, view code and paste in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim CellVal As String
If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("A1:c100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Select Case CellVal
Case "Dog"
Target.Interior.ColorIndex = 5
Case "Cat"
Target.Interior.ColorIndex = 10
Case "Other"
Target.Interior.ColorIndex = 6
Case "Rabbit"
Target.Interior.ColorIndex = 46
Case "Goat"
Target.Interior.ColorIndex = 45
End Select
End If
End Sub

Mike

"Art Caragh" wrote:

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Using VBA: Extending limits of Conditional Formatting

This looks like it will work for me, need some things clarified, firstly I
want the specified row to change to the given back ground color when I update
the value of the progress indicator from 1-16 (each type of application has a
numerical value between 1 and 16 in my sheet) also I have specific colors for
each level 1 through 16, how do I find the correct number to specify the
color I want?

Thank you for your help.

(In addition since this is for work and the e-mail I specify for this is
home would you kindly send me a note to when you do
respond to this?)

Thank you again.
--
Judy Rose Cohen


"JE McGimpsey" wrote:

One way:

In Mike's code, instead of

Target.Interior.ColorIndex = x

use

Target.EntireRow.Interior.ColorIndex = x



In article ,
Chris Pederson wrote:

Hi Mike I'm having a simular problem but I need an entire Row to change
color to change as a result of the value of one cell is there way to do
this using this VBA?




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Using VBA: Extending limits of Conditional Formatting

Mike,
I just found this post, and it works great! It works if you type the value
into the cell, but I need it to execute if data is pasted into the worksheet
and it meets the criteria for each case. Is there something in the code that
can be modified to make that happen rather than having to actually type the
word in each cell?

Thanks,
Steve

"Mike H" wrote:

You can have as many as you want with this. It;s worksheet code so
right-click the tab, view code and paste in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim CellVal As String
If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("A1:c100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Select Case CellVal
Case "Dog"
Target.Interior.ColorIndex = 5
Case "Cat"
Target.Interior.ColorIndex = 10
Case "Other"
Target.Interior.ColorIndex = 6
Case "Rabbit"
Target.Interior.ColorIndex = 46
Case "Goat"
Target.Interior.ColorIndex = 45
End Select
End If
End Sub

Mike

"Art Caragh" wrote:

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using VBA: Extending limits of Conditional Formatting

The code will work if you paste a single cell in that watchrange (A1:C100)?

If you're pasting multiple cells, then the code exits right away:
If Target.Cells.Count 1 Then Exit Sub

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RngToInspect As Range
Dim myIntersect As Range
Dim myCell As Range
Dim myColor As Long

Set RngToInspect = Me.Range("A1:c100") 'change to suit

Set myIntersect = Intersect(RngToInspect, Target)

If myIntersect Is Nothing Then
'not in the range
Exit Sub
End If

For Each myCell In myIntersect.Cells
myColor = -9999
Select Case LCase(myCell.Value)
Case Is = LCase("dog"): myColor = 5
Case Is = LCase("cat"): myColor = 10
Case Is = LCase("Other"): myColor = 6
Case Is = LCase("Rabbit"): myColor = 46
Case Is = LCase("Goat"): myColor = 45
End Select

If myColor < 0 Then
'do nothing
Else
myCell.Interior.ColorIndex = myColor
End If
Next myCell
End Sub


stevedemo77 wrote:

Mike,
I just found this post, and it works great! It works if you type the value
into the cell, but I need it to execute if data is pasted into the worksheet
and it meets the criteria for each case. Is there something in the code that
can be modified to make that happen rather than having to actually type the
word in each cell?

Thanks,
Steve

"Mike H" wrote:

You can have as many as you want with this. It;s worksheet code so
right-click the tab, view code and paste in.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim WatchRange As Range
Dim CellVal As String
If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("A1:c100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Select Case CellVal
Case "Dog"
Target.Interior.ColorIndex = 5
Case "Cat"
Target.Interior.ColorIndex = 10
Case "Other"
Target.Interior.ColorIndex = 6
Case "Rabbit"
Target.Interior.ColorIndex = 46
Case "Goat"
Target.Interior.ColorIndex = 45
End Select
End If
End Sub

Mike

"Art Caragh" wrote:

In a particular column in my spreadsheet I have set up conditional formats to
change the background colour and font colour if certain words are inserted.
The conditional Formatting option on the tool bar gives me a maximum range
of three.

how can i extend this using VBA?


--

Dave Peterson
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
Excel Conditonal Formatting Limits [email protected] Excel Discussion (Misc queries) 1 May 15th 07 04:32 PM
Extending Conditional Formatting Capabilities cardan Excel Programming 0 March 28th 07 07:35 PM
Conditional formatting limits Lucas Lehmer Excel Discussion (Misc queries) 9 May 17th 06 08:41 PM
increase limits for conditional formating for different dates Eqa Excel Programming 3 November 20th 05 10:44 AM
Wrap text limits in Excel 2003 cell formatting Adelrose Excel Discussion (Misc queries) 1 April 19th 05 06:32 PM


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