Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Conditional Formatting Bug w/ relative formula?

Hello -

I have coded up the following to automatically set the Conditional
Formatting for a cell:

lLine = 28

With Range("D" & lLine )
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With

When I run it, the actual Formula is =D37="X" rather than =D28="X". If
I do a Range().Select and then the Selection.FormatConditions.XXX it
works fine. Any idea what that is all about? Am I doing something
wrong here?

Thanks,
Joe

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Conditional Formatting Bug w/ relative formula?

Joe
You need to fully quality your range, otherwise your formulas will be
relative to the activecell:

Public Sub test()
lLine = 28
With ActiveSheet
With .Range("D" & lLine)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine & "=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine & "=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With
End With
End Sub

cheers
Simon

"Joe HM" wrote:

Hello -

I have coded up the following to automatically set the Conditional
Formatting for a cell:

lLine = 28

With Range("D" & lLine )
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With

When I run it, the actual Formula is =D37="X" rather than =D28="X". If
I do a Range().Select and then the Selection.FormatConditions.XXX it
works fine. Any idea what that is all about? Am I doing something
wrong here?

Thanks,
Joe


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default part 2 Conditional Formatting Bug w/ relative formula?

Sorry Joe
Didn't check my last snippet properly
try this:

Public Sub test2()
lLine = 28
With ActiveSheet
With .Range("D" & lLine)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=R" & lLine & "C=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:="=R" & lLine & "C=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With
End With
End Sub

It uses R1C1 instead - seems to work
cheers
Simon

"Joe HM" wrote:

Hello -

I have coded up the following to automatically set the Conditional
Formatting for a cell:

lLine = 28

With Range("D" & lLine )
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With

When I run it, the actual Formula is =D37="X" rather than =D28="X". If
I do a Range().Select and then the Selection.FormatConditions.XXX it
works fine. Any idea what that is all about? Am I doing something
wrong here?

Thanks,
Joe


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Conditional Formatting Bug w/ relative formula?

Since you are using a relative formula, this will be relative to the
activecell. However, in this case, it doesn't appear that you need a
relative formula:

Sub AA()
lLine = 28

With Range("D" & lLine)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=$D$" & lLine & "=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=$D$" & lLine & "=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With

End Sub

works.

--
Regards,
Tom Ogilvy

"Joe HM" wrote in message
ups.com...
Hello -

I have coded up the following to automatically set the Conditional
Formatting for a cell:

lLine = 28

With Range("D" & lLine )
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With

When I run it, the actual Formula is =D37="X" rather than =D28="X". If
I do a Range().Select and then the Selection.FormatConditions.XXX it
works fine. Any idea what that is all about? Am I doing something
wrong here?

Thanks,
Joe



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Conditional Formatting Bug w/ relative formula?

Is it because of the activecell. which you then change.

Try this

lLine = 28

With Range("D" & lLine )
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D$" & lLine &
"=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D$" & lLine &
"=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Joe HM" wrote in message
ups.com...
Hello -

I have coded up the following to automatically set the Conditional
Formatting for a cell:

lLine = 28

With Range("D" & lLine )
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""X"""
.FormatConditions(1).Interior.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:="=$D" & lLine &
"=""Y"""
.FormatConditions(2).Interior.ColorIndex = 5
End With

When I run it, the actual Formula is =D37="X" rather than =D28="X". If
I do a Range().Select and then the Selection.FormatConditions.XXX it
works fine. Any idea what that is all about? Am I doing something
wrong here?

Thanks,
Joe





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default part 2 Conditional Formatting Bug w/ relative formula?

Thanks!

I tried that but it gives me relative columns. I need relative rows
and an absolute column. Is there a way to do that?

Joe

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default part 2 Conditional Formatting Bug w/ relative formula?

Make sure that the correct cell is active when you create the formula.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Joe HM" wrote in message
ups.com...
Thanks!

I tried that but it gives me relative columns. I need relative rows
and an absolute column. Is there a way to do that?

Joe



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Conditional Formatting Bug w/ relative formula?

Hello!

Thanks everybody so much for the help! I did activate the cell and now
it's working properly!

Joe

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 formatting based on relative cell value still learning Excel Worksheet Functions 2 September 29th 09 05:46 PM
Conditional Formatting with relative cells HelenJ Excel Discussion (Misc queries) 8 June 17th 09 05:38 PM
Conditional Formatting Relative to adjacent cells Max Excel Discussion (Misc queries) 2 June 2nd 09 04:50 AM
How do I set conditional formatting relative to another cell -XL20 kboekhoff Excel Discussion (Misc queries) 2 January 5th 09 06:58 AM
Conditional formatting changing relative when copied to other cell robbin Excel Worksheet Functions 1 September 5th 07 11:36 PM


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