View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
voodooJoe voodooJoe is offline
external usenet poster
 
Posts: 43
Default how to select a Row based on contents of a Cell

scott -

conditional formatting is meant to only work on the cell that is being
tested - for example if you have conditional format for "A1" you can state
"If A1100 then make the text blue". You can get it to test for values in
other cells on a limited basis (at least to my knowledge) -- for example

in cell A3 set conditional formatting to: FORMULA IS =($C$3=2)*A3

this basicly uses logic to see if A3 = A3 -- and will only evaluate to true
if $C$3 = 2. so you can trick excel to conditionally format based on values
in other cells. HOWEVER, this is limited as (1) XL only supports 3
conditional formats per cell and (2) it ONLY formats - you cannot use
conditional formatting to perform actions on cells (like DELETE as in your
example)

You could approach your problem several ways. I think the the best solution
is probably to loop through all your tests with an autofilter and perform
the actions within the loop for example:

(the syntax isn't right, just meaning to give you the idea)

set your parameters arrays:

testvalue = array("orange", "CA")
column = (1,3)
action = array("color","delete")
attributes = array("red","na") '''' na used a a placeholder for the 'delete'
action to keep arrays in synch

for i = 1 to 2' that is 2 tests

range.autofilter (where column(i) meets testvalue(i))
for each r in range.specialcells (xlvisible).entirerow
select case action(i)
case "color"
color the visible rows accordiong to the attrributes array
case "delete"
delete the visible rows
end select
next r
next i

this would in effect first color any row where the value in column 1 is
'orange'
then it would delete any row where the value in column 3 is 'CA'

this strategy allows you to have as many actions and tests as you want - and
to change each item at will - w/o having to rewrite the whole script


if you delete, work from the bottom up - because as you delete the rows
below the one you deleted change in number
if you recolor, remember to first set EVERYTHING back to a neutral color or
else you keep the colors you had from the previous macro run


"swintronix" wrote in message
. net...
Hello all... first-time poster here, with what I hope is a simple issue to
bounce off the group. I can't find information about this anywhere. It
isn't specifically addressed in any of the VBA resources I know of....

I believe this is similar to conditional formatting, but I'm trying to
work
with entire rows, rather than just cells. Here's what I'm trying to do,
using VBA...

"If any cell in Column X contains value=Y, then perform Z on the entire
Row."

Examples:

If any cell in Column G contains the word "Apple", then the entire Row
containing that cell shuld be Red.

or

If any cell in Column D contains the word "Ohio", then delete the entire
Row.

Can expression be written in VBA? It seems like conditional formatting,
but
it's not a "per cell" condition. Any suggestions will be greatly
appreciated.

- Scott