PC Review


Reply
Thread Tools Rate Thread

How do I reference cells in CF formula within loop

 
 
John Keith
Guest
Posts: n/a
 
      20th Feb 2010
I want to add a conditional format to every cell in the range A1:C3
where the formula in the conditional format references the cell 10
rows below the current cell, for instance for cell A1 the formula is:

=A1<>A11

and the formula for B1 is:

=B1<>B11

and so on.

I have the following loop to create the conditional formats but I
don't know how to create the formula to reference the cells correctly
as the loop executes.

For Each c In Range("A1:C3)
c.FormatConditions.Delete
c.FormatConditions.Add Type:=xlExpression, _
Formula1:="=A1<>A11
c.FormatConditions(1).Interior.ColorIndex = 36
Next c

How do I use the right variable so the correct formulas are created?

TIA



John Keith
(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      20th Feb 2010
Assuming you want relative referencing, try it this way...

For Each C In Range("A1:C3")
C.FormatConditions.Delete
C.Select
C.FormatConditions.Add Type:=xlExpression, _
Formula1:="=" & C.Address(0, 0) & "<>" & C.Offset(10).Address(0, 0)
C.FormatConditions(1).Interior.ColorIndex = 36
Next

--
Rick (MVP - Excel)


"John Keith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I want to add a conditional format to every cell in the range A1:C3
> where the formula in the conditional format references the cell 10
> rows below the current cell, for instance for cell A1 the formula is:
>
> =A1<>A11
>
> and the formula for B1 is:
>
> =B1<>B11
>
> and so on.
>
> I have the following loop to create the conditional formats but I
> don't know how to create the formula to reference the cells correctly
> as the loop executes.
>
> For Each c In Range("A1:C3)
> c.FormatConditions.Delete
> c.FormatConditions.Add Type:=xlExpression, _
> Formula1:="=A1<>A11
> c.FormatConditions(1).Interior.ColorIndex = 36
> Next c
>
> How do I use the right variable so the correct formulas are created?
>
> TIA
>
>
>
> John Keith
> (E-Mail Removed)


 
Reply With Quote
 
John Keith
Guest
Posts: n/a
 
      20th Feb 2010
Rick,

Thank you, I think that is the new process I needed to learn.

>Assuming you want relative referencing, try it this way...
>
>For Each C In Range("A1:C3")
> C.FormatConditions.Delete
> C.Select
> C.FormatConditions.Add Type:=xlExpression, _
> Formula1:="=" & C.Address(0, 0) & "<>" & C.Offset(10).Address(0, 0)
> C.FormatConditions(1).Interior.ColorIndex = 36
>Next


John Keith
(E-Mail Removed)
 
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
Need to reference two cells to construct formula DaisyGirl Microsoft Excel Programming 1 14th Jun 2009 06:14 PM
when I drag a formula to other cells the reference is the same =?Utf-8?B?c2JhZ3M=?= Microsoft Excel Worksheet Functions 1 9th Nov 2007 08:18 AM
Reference blank cells in formula cycles Microsoft Excel Misc 7 28th Jun 2007 07:25 PM
Putting formula in cells from a loop Andreww Microsoft Excel Programming 1 13th Feb 2007 11:55 AM
My formula screws up other reference cells... =?Utf-8?B?SmFtYnJ1aW5z?= Microsoft Excel Misc 2 28th Feb 2005 02:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:22 PM.