Login|Contact Us
Question and Answer

Programming

Ask a Programming Question, Get an Answer ASAP!

  • Ask A Question
  • Browse Answers
  • Meet The Experts
  • How JustAnswer Works

Counting Visible rows only using vba code I have a table

 
J. Mar's Avatar
  • Answered by:J. Mar
  • Consultant
  • Positive Feedback: 100.0 %
  • Accepted Answers: 120
Verified Expert
in Programming

Recent Feedback

Positive
Great job, thank you!
Positive
Could not be any more satisfied. He took on a problem that others said couldn't...
Positive
Absolutely wonderful, exactly what I needed and within a time frame that amazes...
Positive
Thanks John - that's exactly what I meant! Have good day.
Positive
Very impressed, thanks for your help. Saved me a lot of time.
Positive
I thought the resolution to my problem was not possible. I am extremely...
Positive
Thanks again! You are my hero!!
Positive
Awesome!!! Very timely reponse and it's worked perfect! Thank You!
Positive
Quick response and got the right answer the first time.
Positive
Just and outstanding "Expert" with in-depth knowledge of Excel Programming and...

Customer Question

Counting Visible rows only using vba code:
I have a table (tblProbRep) that gets filterred. i need to count the filterred visible rows only. What would the code look like if I click on a button and it counts only the visible rows and gives me the amount (like 9)
I then need to specify that in column H in the number of rows visible counted is the answer I want placed into a cell.

for instance:
'RowCount - is the amount of visible rows
'....code to count the visible rows.......
Sheets("Sheet1").Range("A1")=Sheets("Sheets2").Range("tblProbRep").Cells(RowCount,"H")

or something to that effect.

Please can someone help.
Kind Regards
XXXXXXXX

 

Optional Information:
Computer OS: Windows 7
Browser: IE
Programming Language: VBA

Submitted: 650 days and 4 hours ago.
Category: Programming
Value: R 181
Status: CLOSED
Picture
Expert:  J. Mar replied 650 days and 4 hours ago.

Thank you for asking your question on JustAnswer. My name is XXXXX XXXXX X will be happy to help you.

 

You can creat a function or paste the following in a stand alone module.

 

Function CountVisibleFilterRows(MyRange As Range) As Long
On Error Resume Next
CountVisibleFilterRows = MyRange.SpecialCells(xlCellTypeVisible).Count
End Function

 

Then you can access the function with this, for example;

 

CountVisibleFilterRows(Range("A1:A20")) in Excel formula or

 

in VBA use;

 

Application.WorksheetFunction.CountVisibleFilterRows(Range("A1:A20"))

Customer replied 650 days and 3 hours ago.

Hi there

Do I just use it as is?

Function CountVisibleFilterRows(MyRange As Range) As Long
On Error Resume Next
CountVisibleFilterRows = MyRange.SpecialCells(xlCellTypeVisible).Count
End Function

Application.WorksheetFunction.CountVisibleFilterRows(Range("A1:A20"))

or do i substitute my information in there and what goes where?

When I use the information in my file, it gives me 0 not 3 or something no matter what is visible.

Picture
Expert:  J. Mar replied 650 days and 3 hours ago.

Sorry, the function I mentioned before should be re-written as follows;

 

Substitute your information where necessary

 

Function CountVisibleFilterRows(ByVal Sh As Worksheet)
Dim Target As Range
Dim c As Range
Dim i As Long
'If the Filter is not used
If Sh.FilterMode = False Then
CountVisibleFilterRows = 0
Exit Function
End If
Set Target = Sh.AutoFilter.Range
For Each c In Target.SpecialCells(xlCellTypeVisible).Areas
i = i + c.Rows.Count
Next
CountVisibleFilterRows = i - 1 '-1 stands for remove header row
End Function

J. Mar40723.6230206829

Picture
Expert:  J. Mar replied 650 days and 3 hours ago.

Here is an example how to use in VBA

 

Application.WorksheetFunction.FilteredRowsCount(ActiveSheet) ; where "ActiveSheet" is the Worksheet your filter is on

Customer replied 649 days and 8 hours ago.

Thanks for trying to help

 

I actually got the code from another website and changed it a little

it goes like this:

 

Dim rng As Range

Dim RowCount as Integer, r as Integer


Set rng = Sheets("ProblemReporting").AutoFilter.Range
RowCount = rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1
'MsgBox RowCount
r = RowCount
txtProjProgUpd.Value = Sheets("ProblemReporting").Range("tblProbRep").Cells(r, 2)

Picture
Expert:  J. Mar replied 649 days and 7 hours ago.

Thank you

 
Tweet

6 Programmers are Online Right Now

Ask Your Question Now
Programming Questions Date Submitted
is there a python programming person available 3/28/2013
Write a menu-driven program that allows users do two options: Option 3/27/2013
1. Which one of the following control structures provides for 3/27/2013
JavaScript: Multiple Choice Questionnaire 3/25/2013
RA-211 3/24/2013
How do you create a searchable public Google drive folder in 3/24/2013
RA-211 3/24/2013
I am an entrepreneur with no current coding skills, but an 3/23/2013
I have base code in VBA that opens all excel files from a folder 3/23/2013
Program in C++ 3/23/2013
RSS
Next 10 >
Ask A Programmer
Type Your Programming Question Here...
characters left:

Top Programming Experts

See More Programmers

In The News

Nbc
Washington Post
New York Times
Cnn
Learn More

How It Works

  • Ask an Expert
  • Get a Professional Answer
  • Ask Followup Questions
  • 100% Satisfaction Guarantee
Learn More
close
Find Expert answers related to your question.
Sign up using email
We will never post anything without your permission.
Already have an account? Sign in

Ask a Programmer

Get a Professional Answer. 100% Satisfaction Guaranteed.
264 Programmers are Online Now
Type Your Programming Question Here...
characters left:
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.
Truste
Contact Us | Terms of Service | Privacy & Security | About Us
© 2003-2013 JustAnswer LLC