PC Review


Reply
Thread Tools Rate Thread

Conditional Formatting with reference to another worksheet VBA

 
 
michaelsdumas@gmail.com
Guest
Posts: n/a
 
      22nd Jul 2009
I am trying to use conditional formating from input from a second
sheet.

The ranges are relative: offset by +5 vertically. I have tried the
code a few ways, but I cannot figure out how to translate the range
from one sheet to another.

Here is what I have:


Private Sub Worksheet_Change(ByVal RoadShow As Excel.Range)
Dim Source As Range
Dim Target As Range
Dim CellVal As Integer
Dim CellTar As Integer
Dim LastLoc As Range

If RoadShow.Cells.Count > 1 Then Exit
If RoadShow = "" Or Not IsNumeric(RoadShow) Then Exit Sub
CellVal = RoadShow
LastLoc = RoadShow.Address

Set Target = Worksheets("Costco").Range(LastLoc)
Set Source = Range("C4:AB45")

If Not Intersect(RoadShow, Source) Is Nothing Then

Target.Offset(5, 0).Select
CelTar = Target.Interior.ColorIndex
If CellVal = 1 Then
Select Case CellTar
Case 27
With Target.Interior
.ColorIndex = 55
.Pattern = xlPatternVertical
.PatternColorIndex = 27
End With
Case 42
With Target.Interior
.ColorIndex = 55
.Pattern = xlPatternVertical
.PatternColorIndex = 42
End With
Case ""
Target.Interior.ColorIndex = 55
End Select
End If
End If
End Sub



Thank you for the help.
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      22nd Jul 2009
I don't think you can apply CF to sheets other than the activesheet, but see
this link for a possible workaround:
http://www.cpearson.com/excel/cformatting.htm

Good luck,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"(E-Mail Removed)" wrote:

> I am trying to use conditional formating from input from a second
> sheet.
>
> The ranges are relative: offset by +5 vertically. I have tried the
> code a few ways, but I cannot figure out how to translate the range
> from one sheet to another.
>
> Here is what I have:
>
>
> Private Sub Worksheet_Change(ByVal RoadShow As Excel.Range)
> Dim Source As Range
> Dim Target As Range
> Dim CellVal As Integer
> Dim CellTar As Integer
> Dim LastLoc As Range
>
> If RoadShow.Cells.Count > 1 Then Exit
> If RoadShow = "" Or Not IsNumeric(RoadShow) Then Exit Sub
> CellVal = RoadShow
> LastLoc = RoadShow.Address
>
> Set Target = Worksheets("Costco").Range(LastLoc)
> Set Source = Range("C4:AB45")
>
> If Not Intersect(RoadShow, Source) Is Nothing Then
>
> Target.Offset(5, 0).Select
> CelTar = Target.Interior.ColorIndex
> If CellVal = 1 Then
> Select Case CellTar
> Case 27
> With Target.Interior
> .ColorIndex = 55
> .Pattern = xlPatternVertical
> .PatternColorIndex = 27
> End With
> Case 42
> With Target.Interior
> .ColorIndex = 55
> .Pattern = xlPatternVertical
> .PatternColorIndex = 42
> End With
> Case ""
> Target.Interior.ColorIndex = 55
> End Select
> End If
> End If
> End Sub
>
>
>
> Thank you for the help.
>

 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      22nd Jul 2009
You can not select on a non active sheet. That being said you have no need to
select. Target is the range so just use that...

Private Sub Worksheet_Change(ByVal RoadShow As Excel.Range)
Dim Source As Range
Dim Target As Range
Dim CellVal As Integer
Dim CellTar As Integer
Dim LastLoc As Range

If RoadShow.Cells.Count > 1 Then Exit
If RoadShow = "" Or Not IsNumeric(RoadShow) Then Exit Sub
CellVal = RoadShow
LastLoc = RoadShow.Address

Set Target = Worksheets("Costco").Range(LastLoc).offset(5,0) 'the change
Set Source = Range("C4:AB45")

If Not Intersect(RoadShow, Source) Is Nothing Then

CelTar = Target.Interior.ColorIndex
If CellVal = 1 Then
Select Case CellTar
Case 27
With Target.Interior
.ColorIndex = 55
.Pattern = xlPatternVertical
.PatternColorIndex = 27
End With
Case 42
With Target.Interior
.ColorIndex = 55
.Pattern = xlPatternVertical
.PatternColorIndex = 42
End With
Case ""
Target.Interior.ColorIndex = 55
End Select
End If
End If
End Sub


--
HTH...

Jim Thomlinson


"(E-Mail Removed)" wrote:

> I am trying to use conditional formating from input from a second
> sheet.
>
> The ranges are relative: offset by +5 vertically. I have tried the
> code a few ways, but I cannot figure out how to translate the range
> from one sheet to another.
>
> Here is what I have:
>
>
> Private Sub Worksheet_Change(ByVal RoadShow As Excel.Range)
> Dim Source As Range
> Dim Target As Range
> Dim CellVal As Integer
> Dim CellTar As Integer
> Dim LastLoc As Range
>
> If RoadShow.Cells.Count > 1 Then Exit
> If RoadShow = "" Or Not IsNumeric(RoadShow) Then Exit Sub
> CellVal = RoadShow
> LastLoc = RoadShow.Address
>
> Set Target = Worksheets("Costco").Range(LastLoc)
> Set Source = Range("C4:AB45")
>
> If Not Intersect(RoadShow, Source) Is Nothing Then
>
> Target.Offset(5, 0).Select
> CelTar = Target.Interior.ColorIndex
> If CellVal = 1 Then
> Select Case CellTar
> Case 27
> With Target.Interior
> .ColorIndex = 55
> .Pattern = xlPatternVertical
> .PatternColorIndex = 27
> End With
> Case 42
> With Target.Interior
> .ColorIndex = 55
> .Pattern = xlPatternVertical
> .PatternColorIndex = 42
> End With
> Case ""
> Target.Interior.ColorIndex = 55
> End Select
> End If
> End If
> End Sub
>
>
>
> Thank you for the help.
>

 
Reply With Quote
 
michaelsdumas@gmail.com
Guest
Posts: n/a
 
      22nd Jul 2009
Thanks Ryan, I am honestly looking for an event based on a relative
cell in another worksheet. This does not have to be specific.

Thanks.

On Jul 22, 2:41*pm, ryguy7272 <ryguy7...@discussions.microsoft.com>
wrote:
> I don't think you can apply CF to sheets other than the activesheet, but see
> this link for a possible workaround:http://www.cpearson.com/excel/cformatting.htm
>
> Good luck,
> Ryan---
>


 
Reply With Quote
 
michaelsdumas@gmail.com
Guest
Posts: n/a
 
      22nd Jul 2009
Thank you. There is something odd going on now.

I am getting a do sub error on the line: If RoadShow.Cells.Count > 1
Then Exit


On Jul 22, 3:38*pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com> wrote:
> You can not select on a non active sheet. That being said you have no need to
> select. Target is the range so just use that...
>
> Private Sub Worksheet_Change(ByVal RoadShow As Excel.Range)
> Dim Source As Range
> Dim Target As Range
> Dim CellVal As Integer
> Dim CellTar As Integer
> Dim LastLoc As Range
>
> If RoadShow.Cells.Count > 1 Then Exit
> * * If RoadShow = "" Or Not IsNumeric(RoadShow) Then Exit Sub
> * * CellVal = RoadShow
> * * LastLoc = RoadShow.Address
>
> * * Set Target = Worksheets("Costco").Range(LastLoc).offset(5,0) 'the change
> * * Set Source = Range("C4:AB45")
>
> * * If Not Intersect(RoadShow, Source) Is Nothing Then
>
> * * CelTar = Target.Interior.ColorIndex
> * * If CellVal = 1 Then
> * * * * Select Case CellTar
> * * * * * * Case 27
> * * * * * * * * With Target.Interior
> * * * * * * * * .ColorIndex = 55
> * * * * * * * * .Pattern = xlPatternVertical
> * * * * * * * * .PatternColorIndex = 27
> * * * * * * * * End With
> * * * * * * *Case 42
> * * * * * * * * With Target.Interior
> * * * * * * * * .ColorIndex = 55
> * * * * * * * * .Pattern = xlPatternVertical
> * * * * * * * * .PatternColorIndex = 42
> * * * * * * * * End With
> * * * * * * Case ""
> * * * * * * * * Target.Interior.ColorIndex = 55
> * * * * End Select
> * * End If
> End If
> End Sub
>
> --
> HTH...
>
> Jim Thomlinson
>
>
>
> "michaelsdu...@gmail.com" wrote:
> > I am trying to use conditional formating from input from a second
> > sheet.

>
> > The ranges are relative: offset by +5 vertically. I have tried the
> > code a few ways, but I cannot figure out how to translate the range
> > from one sheet to another.

>
> > Here is what I have:

>
> > Private Sub Worksheet_Change(ByVal RoadShow As Excel.Range)
> > Dim Source As Range
> > Dim Target As Range
> > Dim CellVal As Integer
> > Dim CellTar As Integer
> > Dim LastLoc As Range

>
> > If RoadShow.Cells.Count > 1 Then Exit
> > * * If RoadShow = "" Or Not IsNumeric(RoadShow) Then Exit Sub
> > * * CellVal = RoadShow
> > * * LastLoc = RoadShow.Address

>
> > * * Set Target = Worksheets("Costco").Range(LastLoc)
> > * * Set Source = Range("C4:AB45")

>
> > * * If Not Intersect(RoadShow, Source) Is Nothing Then

>
> > * * Target.Offset(5, 0).Select
> > * * CelTar = Target.Interior.ColorIndex
> > * * If CellVal = 1 Then
> > * * * * Select Case CellTar
> > * * * * * * Case 27
> > * * * * * * * * With Target.Interior
> > * * * * * * * * .ColorIndex = 55
> > * * * * * * * * .Pattern = xlPatternVertical
> > * * * * * * * * .PatternColorIndex = 27
> > * * * * * * * * End With
> > * * * * * * *Case 42
> > * * * * * * * * With Target.Interior
> > * * * * * * * * .ColorIndex = 55
> > * * * * * * * * .Pattern = xlPatternVertical
> > * * * * * * * * .PatternColorIndex = 42
> > * * * * * * * * End With
> > * * * * * * Case ""
> > * * * * * * * * Target.Interior.ColorIndex = 55
> > * * * * End Select
> > * * End If
> > End If
> > End Sub

>
> > Thank you for the help.


 
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
conditional formatting = or > cell reference + 2 Whitney Microsoft Excel Misc 1 19th Apr 2010 08:10 PM
reference another cell in conditional formatting Rose Microsoft Excel Worksheet Functions 3 27th Feb 2009 09:17 PM
Reference to functions in Conditional Formatting Atreides Microsoft Excel Programming 2 14th May 2008 03:45 AM
cell reference changes and conditional formatting =?Utf-8?B?TWFnZ2llIEJvYnk=?= Microsoft Excel Worksheet Functions 4 11th Jun 2006 04:43 AM
Conditional Formatting with Relative Reference. Swiatkowski Peter Microsoft Excel Discussion 4 15th Dec 2005 08:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 PM.