473,557 Members | 2,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with counting visible rows after filter in excel

43 New Member
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
Jul 7 '16 #1
2 6207
32,564 Recognized Expert Moderator MVP
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
2 New Member
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
  3. count = worksheetfunction.subtotal(103, ActiveSheet.Range("$A$1:$BU$87").columns(1)) - 1
Hope it helps
Jul 8 '16 #3

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

Similar topics

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 to use the =Count(*) in the textbox to get the total rows returned form the Query,but is there a way to filter them? He has a feild that is called...
by: sree ram | last post by:
code for getting maximum rows in excel sheet using perl script
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
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!
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 automate it and I'm almost there. Using VBA i've got the filters to select the criteria I need but I can't get it to count the rows that are visible. the...
by: sasen903 | last post by:
private String GetExcelSheetNames(string excelFile) { OleDbConnection objConn = null; SqlConnection objSqlConn = null; System.Data.DataTable dt = null; try { // Connection String. Change the excel file to the file you
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 spreadsheet and continue until all the rows are in different excel spreadsheets. My looping / counting code is pulling in all of the rows instead...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.