PC Review


Reply
Thread Tools Rate Thread

Conditional Formatting Strangeness

 
 
Keith Wilby
Guest
Posts: n/a
 
      23rd Jul 2007
I'm working from an Access database to conditionally format cells in Excel.
Here's a snippet of my code. I don't pretend to understand how some of it
works, it was kindly supplied by Bernie Deitrick.

Set objRange = objXL.Intersect(objSht.Range("K2:IV65536"),
objSht.UsedRange) 'Start from Row 2
With objRange
.Select
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess,
Formula1:="=" & .Cells(1, 0).Address(False, False)
.FormatConditions(1).Interior.ColorIndex = 3 'Conditionally
format cells red
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlGreater, Formula1:="=" & .Cells(1, 0).Address(False, False)
.FormatConditions(2).Interior.ColorIndex = 4 'Conditionally
format cells red
End With

When I manually select cell K2 in Excel and look up the conditional
formatting it references cell T2 instead of cell J2. That just happens to
be an offset of 10. I'm *sure* this code used to work but I can't for the
life of me work out why it's behaving this way. Any clues anyone?

Many thanks.

Keith.

 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      23rd Jul 2007
With your relative addressing everything is relative to the active cell, try
changing -
).Address(False, False)
to
).Address

Regards,
Peter T

"Keith Wilby" <(E-Mail Removed)> wrote in message
news:46a4c2f5$(E-Mail Removed)...
> I'm working from an Access database to conditionally format cells in

Excel.
> Here's a snippet of my code. I don't pretend to understand how some of it
> works, it was kindly supplied by Bernie Deitrick.
>
> Set objRange = objXL.Intersect(objSht.Range("K2:IV65536"),
> objSht.UsedRange) 'Start from Row 2
> With objRange
> .Select
> .FormatConditions.Delete
> .FormatConditions.Add Type:=xlCellValue, Operator:=xlLess,
> Formula1:="=" & .Cells(1, 0).Address(False, False)
> .FormatConditions(1).Interior.ColorIndex = 3

'Conditionally
> format cells red
> .FormatConditions.Add Type:=xlCellValue,
> Operator:=xlGreater, Formula1:="=" & .Cells(1, 0).Address(False, False)
> .FormatConditions(2).Interior.ColorIndex = 4

'Conditionally
> format cells red
> End With
>
> When I manually select cell K2 in Excel and look up the conditional
> formatting it references cell T2 instead of cell J2. That just happens to
> be an offset of 10. I'm *sure* this code used to work but I can't for the
> life of me work out why it's behaving this way. Any clues anyone?
>
> Many thanks.
>
> Keith.
>



 
Reply With Quote
 
Keith Wilby
Guest
Posts: n/a
 
      23rd Jul 2007
"Peter T" <peter_t@discussions> wrote in message
news:%(E-Mail Removed)...
> With your relative addressing everything is relative to the active cell,
> try
> changing -
> ).Address(False, False)
> to
> ).Address
>


Hi Peter, I neglected to mention what the conditional formatting was but
you seem to have sussed it. The cell referencing seems to be OK with your
suggested mod, what do the "False" arguments actually do?

Thanks.

Keith.

 
Reply With Quote
 
Keith Wilby
Guest
Posts: n/a
 
      23rd Jul 2007
"Peter T" <peter_t@discussions> wrote in message
news:%(E-Mail Removed)...
> With your relative addressing everything is relative to the active cell,
> try
> changing -
> ).Address(False, False)
> to
> ).Address
>


Hi Peter, I spoke too soon as all of the cells in the range now reference
row 2.

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      23rd Jul 2007
Actually your original code seems fine, providing the active (selected) cell
is K2, thereafter everything is relative. In your OP you say when you select
K2 the CF formula refers to T2, that would imply when the CF was applied A2
was active which seems odd looking at your code.

in your adjacent post
>what do the "False" arguments actually do?


They return relative address without the $'s

Msgbox activecell.address & vbcr & activecell.address(false,false)

Regards,
Peter T

"Keith Wilby" <(E-Mail Removed)> wrote in message
news:46a4c9df$(E-Mail Removed)...
> "Peter T" <peter_t@discussions> wrote in message
> news:%(E-Mail Removed)...
> > With your relative addressing everything is relative to the active cell,
> > try
> > changing -
> > ).Address(False, False)
> > to
> > ).Address
> >

>
> Hi Peter, I spoke too soon as all of the cells in the range now reference
> row 2.
>



 
Reply With Quote
 
Keith Wilby
Guest
Posts: n/a
 
      24th Jul 2007
"Peter T" <peter_t@discussions> wrote in message
news:%(E-Mail Removed)...
> Actually your original code seems fine, providing the active (selected)
> cell
> is K2, thereafter everything is relative. In your OP you say when you
> select
> K2 the CF formula refers to T2, that would imply when the CF was applied
> A2
> was active which seems odd looking at your code.
>


Hi again Peter, thanks for your patience. At runtime, in the immediate
window, when I paste

?objXL.Intersect(objSht.Range("K2:IV65536"), objSht.UsedRange)

I get a "Type mismatch" error. Any ideas why that might be?

Regards,
Keith.

 
Reply With Quote
 
Keith Wilby
Guest
Posts: n/a
 
      24th Jul 2007
"Peter T" <peter_t@discussions> wrote in message
news:%(E-Mail Removed)...
> Actually your original code seems fine, providing the active (selected)
> cell
> is K2, thereafter everything is relative. In your OP you say when you
> select
> K2 the CF formula refers to T2, that would imply when the CF was applied
> A2
> was active which seems odd looking at your code.
>


Hi Peter, please ignore my earlier post today. It would seem that my Access
VBA project had become corrupted because running a /decompile and then
re-compiling seems to have rectified the problem.

Thanks for your time.

Regards,
Keith.

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      24th Jul 2007
"Keith Wilby" <(E-Mail Removed)> wrote in message
news:46a5ab5b$(E-Mail Removed)...
> "Peter T" <peter_t@discussions> wrote in message
> news:%(E-Mail Removed)...
> > Actually your original code seems fine, providing the active (selected)
> > cell
> > is K2, thereafter everything is relative. In your OP you say when you
> > select
> > K2 the CF formula refers to T2, that would imply when the CF was applied
> > A2
> > was active which seems odd looking at your code.
> >

>
> Hi Peter, please ignore my earlier post today. It would seem that my

Access
> VBA project had become corrupted because running a /decompile and then
> re-compiling seems to have rectified the problem.
>
> Thanks for your time.
>
> Regards,
> Keith.


Glad you got it working with the recompile, but just wondering if that might
be a coincidence. Looking at your original code again -
Set objRange = objXL.Intersect(objSht.Range("K2:IV65536"),objSht.UsedRange)

If the no part of the Usedrange exists within "K2:IV65536" objRange will
remain as 'Nothing' causing the rest of your code to work incorrectly.

Regards,
Peter T


 
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 strangeness Allenx Microsoft Excel Worksheet Functions 0 14th Mar 2007 02:58 PM
Conditional Formatting No Longer Conditional in 2007 Beta =?Utf-8?B?Q2FjdHVhci1Oby1KdXRzdQ==?= Microsoft Excel Crashes 0 17th Nov 2006 10:01 PM
Conditional formatting strangeness duncan79 Microsoft Excel Misc 5 18th May 2006 05:02 AM
Conditional formatting strangeness christopherp Microsoft Excel Misc 13 6th Mar 2006 12:51 PM
Datalist Formatting Strangeness Joe Microsoft ASP .NET 3 18th Oct 2003 05:13 AM


Features
 

Advertising
 

Newsgroups
 


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