View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Ken Ken is offline
external usenet poster
 
Posts: 590
Default A little Macro Help Please ...

One more thing ... I have "multiple" checks to make & I wish to "clear
contents" each time Criteria found ... & I wish to MOVE ON each time Criteria
is NOT found.

Thanks ... Kha

"mark" wrote:

Ahh... good. Sorry... I wasn't sure what you meant; perhaps I didn't read
carefully enough the first time.. sorry.

Anyway, here, this will do what you need.

'***********
Selection.AutoFilter Field:=1, Criteria1:="<32*", Operator:=xlAnd
Range("A3:N2000").Select

If Range("a3:N2000").SpecialCells(xlCellTypeVisible). Count <
Range("a3:N2000").Cells.Count Then

Selection.ClearContents

End If
'************

The special cells xlcelltypevisible bit will check if the autofilter has
hidden any rows, or not, and only run the clearcontents if the two counts
(total cells vs. visible cells) don't match.



"Ken" wrote:

What I wish:

1: Criteria found ... Clear visible cells in Range A3:N2000.
2: Criteria not found ...Move on without clearing anything.

As it is:

1: Criteria found ... Clears visible cells in Range A3:N2000.
2: Criteria not found ... Clears EVERYTHING in Range A3:N2000.

Thanks ... Kha




"mark" wrote:

your code is set to clear everything left visible in the range A3:N2000 after
the application of the AutoFilter.

what do you want it to do? You didn't actually say.

If you want it to apply the filter, but not delete anything, then just take
out the two line:

Selection.ClearContents





"Ken" wrote:

Excel2003 ... I know nothing of VB Code ... I record Macros only & then
perform a little creative cut/paste as needed ... That said ... I have the
following recorded Macro instruction:

Range("A2").Select
Selection.AutoFilter Field:=1, Criteria1:="<32*", Operator:=xlAnd
Range("A3:N2000").Select
Selection.ClearContents

Issue is ... ALL Data is cleared from the Range ("A3:N2000") when the
Criteria1:="<32*" is NOT found.

When Criteria1 is found ... no problem.
When Criteria1 is not found ... it sucks to be me.

My Thanks to those that support these boards ... Kha