Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default My Autofilter is overzealous!

Hi guys,

I have a macro that does a filter on a named range in another open workbook
and copies the results to the active cell. This works fine except when the
search and filter comes up with nothing (no hits) then the entire named
range is copied!. I would have thought because there is an IF in there it
would do nothing with no hits. I'm sure this is simple but I cant get it!
A couple of other questions if I may. Is there an easier way of getting the
weekday from a serial than WeekdayName(Weekday(R1C4))? It seems a bit long
winded.
What the easiest way to focus on the first empty cell in a column?
Hope you can help

Thanks
Mark

Sub Test4()
'
' Test4 Macro
' Macro recorded 31/10/2003 by Mark
' Keyboard Shortcut: Ctrl+i
'
Let sheetDate = Range("I1").Value 'gets date value
if Selection.AutoFilter Field:=7, Criteria1:="BARSAC" then
Range("ProgramData").Select
Range("ProgramData").Activate
Selection.Copy
Windows("BARSAC.xls").Activate

ActiveCell.Range("D1").Value = sheetDate 'paste date
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(-1, 3).Font.Bold = True
With ActiveCell.Offset(-1, 0)
.FormulaR1C1 = WeekdayName(Weekday(R1C4))
.Font.Bold = True
End With

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default My Autofilter is overzealous!

You can check the count of matching rows with this function:

Function RowMatchCount(WS As Worksheet) As Long
Dim MatchCount As Long, Area As Range
For Each Area In
WS.Range("_FilterDatabase").SpecialCells(xlCellTyp eVisible).Areas
MatchCount = MatchCount + Area.Rows.Count
Next
RowMatchCount = MatchCount - 1
End Function

Sub Demo()
MsgBox RowMatchCount(Worksheets("Sheet1"))
End Sub


--
Jim Rech
Excel MVP


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
excel 2007 autofilter change to 2003 autofilter functionality? jonnybrovo815 Excel Discussion (Misc queries) 1 April 19th 10 10:05 PM
2007 excel autofilter back to 2003 autofilter? jonnybrovo815 Excel Discussion (Misc queries) 3 April 19th 10 08:11 PM
2007 excel autofilter change back to 2003 autofilter? jonnybrovo815 Excel Discussion (Misc queries) 1 April 19th 10 05:53 PM
2007 Autofilter worse than 2003 Autofilter jsky Excel Discussion (Misc queries) 9 October 31st 07 12:14 AM
How to Sort within AutoFilter with Protection on (and AutoFilter . giblon Excel Discussion (Misc queries) 1 February 16th 06 12:23 PM


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