Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

Solved: Excel 07 VBA - Counting all Visible rows after a filter was applied.


(!)

TMeerkat's Avatar
TMeerkat TMeerkat is offline
Computer Specs
Junior Member with 12 posts.
THREAD STARTER
 
Join Date: Jun 2011
Location: South Africa
Experience: Beginner
29-Jun-2011, 08:28 AM #1
Solved: Excel 07 VBA - Counting all Visible rows after a filter was applied.
Hi there

I would like to count the visible rows of a table (tblProbRep) that has been filterred and then to select the last cell in column H to copy to another sheet.
I know the code for all except how to count only visible rows in vba .
Please can someone assist.

Thanks you
TMeerkat
CDHarm's Avatar
CDHarm CDHarm is offline
Computer Specs
Member with 231 posts.
 
Join Date: May 2011
Location: Biloxi
Experience: Intermediate
29-Jun-2011, 11:51 AM #2
TMeekat,

Here's a bit of code that I use to count the "Visible" rows.


Code:
Dim Myval as Intiger
Myval = .Range("c2:c" & lrow).SpecialCells(xlCellTypeVisible).Count
TMeerkat's Avatar
TMeerkat TMeerkat is offline
Computer Specs
Junior Member with 12 posts.
THREAD STARTER
 
Join Date: Jun 2011
Location: South Africa
Experience: Beginner
30-Jun-2011, 05:30 AM #3
Hi there

When I use this code
Dim Myval As Integer
Myval = Sheets("ProblemReporting").Range("tblProbRep").SpecialCells(xlCellTypeVisib le).Count

MsgBox "This is " & Myval, vbOKCancel

it gives me 15 when there is only 6 rows and only 3 rows are visible.
Why is that?

Did I do something wrong?
AD_Taylor's Avatar
AD_Taylor AD_Taylor is offline
Computer Specs
Member with 93 posts.
 
Join Date: Jan 2010
Experience: Intermediate
30-Jun-2011, 07:55 AM #4
Is the range "tblProbRep" 5 columns wide?

If so you because you are counting cells that are visible you have 3 rows by 5 columns = 15 cells visible?

You could try:
Code:
Myval = Sheets("ProblemReporting").Range("tblProbRep").Columns(1).SpecialCells(xlCellTypeVisible).Count
This should narrow the range down to just the first column so that it will only count the rows.

Hope this helps!
Adam
CDHarm's Avatar
CDHarm CDHarm is offline
Computer Specs
Member with 231 posts.
 
Join Date: May 2011
Location: Biloxi
Experience: Intermediate
30-Jun-2011, 12:35 PM #5
Adam,

Thanks for the answer. I learned something from this.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑