473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with counting visible rows after filter in excel

lilp32
43
I am trying to set up a prompt to print only if filtered rows are visible. I need to count the visible rows after the filter is applied (not including the header). I have tried various combinations but nothing seems to work every time.

Here is what I have:

Expand|Select|Wrap|Line Numbers
  1. ActiveSheet.Range("$A$1:$BU$87").AutoFilter Field:=17, Criteria1:="="
  2. ActiveSheet.Range("$A$1:$BU$87").AutoFilter Field:=1, Criteria1:="="
  3.     If ActiveSheet.AutoFilter.Range.Columns(2).SpecialCells(xlCellTypeVisible).Cells.Count - 1 > 1 Then
  4.     Yprint = MsgBox("There are new patients to enroll.  Do you want to print today's list?", vbYesNo + vbQuestion, "Print")
  5.     If Yprint = vbYes Then
  6.     ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
  7. End If
  8. Else: MsgBox ("No new patients today")
  9. End If
  10.  
Jul 7 '16 #1
2 6164
NeoPa
32,556 Expert Mod 16PB
If you use Ctrl-End when there are no rows except the header then the .Row of that resultant cell will be 1 (or whatever row your header is on).
Expand|Select|Wrap|Line Numbers
  1. If ActiveCell.SpecialCells(xlLastCell).Row = 1 Then
  2.     Debug.Print "No Rows";
  3. Else
  4.     Debug.Print "Some Rows";
  5. End If
NB. Please only use indenting in code if you do it in a way that makes sense. Indented code in the wrong places is even harder to read and work with than completely non-indented code - which is more than bad enough.
Jul 7 '16 #2
Use subtotal with the count function to get that. and subtract 1 to remove the header.

Expand|Select|Wrap|Line Numbers
  1. dim count as long
  2.  
  3. count = worksheetfunction.subtotal(103, ActiveSheet.Range("$A$1:$BU$87").columns(1)) - 1
  4.  
Hope it helps
Jul 8 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: PlimoMan | last post by:
Im helping a friend with a little access and we're both stuck on this one part. Hes using a query to create a report and he wanted to add a total of certain rows in teh header or footer. We know how...
1
by: sree ram | last post by:
code for getting maximum rows in excel sheet using perl script
1
by: ronakinuk | last post by:
how to insert multiple rows in excel using vba how to insert multiple rows in excel using vba how to insert multiple rows in excel using vba
3
by: Eddie Rivera | last post by:
Does anyone know of a formula to highlight rows in Excel? I have used Conditional Formatting but I need a formula to find past due and upcoming dates. Thanks in advance for your help!
2
by: scrapcode | last post by:
Hi guys, this should be an easy one. I have an Excel workbook that I need to run a filter with lots of criteria on a number of different sheets and count the results every day. I'm looking to...
2
by: sasen903 | last post by:
private String GetExcelSheetNames(string excelFile) { OleDbConnection objConn = null; SqlConnection objSqlConn = null; ...
1
by: bgrove | last post by:
Hi Need help with my code. I have an access query with 1.6 million rows. I need to count 4000 rows then move those rows to an excel spreadsheet then count the next 4000 rows and move to a new excel...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.