Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:01:56+00:00 2026-06-14T11:01:56+00:00

This is another weird one. I have this code which takes data from one

  • 0

This is another weird one.

I have this code which takes data from one sheet using filters and is using the Range.SpecialCells() method to find the appropriate rows to copy and paste. However, if I used Rows().SpecialCells() or if I used the row property of the range returned by SpecialCells the count of rows is wrong. Here’s what I mean:

With Worksheets("ret-" & sNumRet)
    .EnableAutoFilter = True
    .AutoFilter.Range.AutoFilter Field:=3, Criteria1:=sSection
    iLast = Range("C1").End(xlDown).Row
    numRows = .Range("B2:B" & iLast).SpecialCells(xlCellTypeVisible).Cells.Count
End With

This code yields around 8k rows which is a number that makes sense.

With Worksheets("ret-" & sNumRet)
    .EnableAutoFilter = True
    .AutoFilter.Range.AutoFilter Field:=3, Criteria1:=sSection
    iLast = Range("C1").End(xlDown).Row
    numRows = .Rows("2:" & iLast).SpecialCells(xlCellTypeVisible).Rows.Count
End With

Yields 4 as a result.

With Worksheets("ret-" & sNumRet)
    .EnableAutoFilter = True
    .AutoFilter.Range.AutoFilter Field:=3, Criteria1:=sSection
    iLast = Range("C1").End(xlDown).Row
    numRows = .Range("B2:B" & iLast).SpecialCells(xlCellTypeVisible).Rows.Count
End With

Also yields 4 as a result. Both of those are of course wrong. I have 45k rows of data and I can see that at least a few thousands are displayed using the filter. Is there some difference of meaning I am missing between those statements ? I would expect them to be almost equivalent in the context here.

Thanks !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:01:57+00:00Added an answer on June 14, 2026 at 11:01 am

    This doesn’t really have to do with SpecialCells, rather how Excel counts rows. Rows.Count returns counts for each contiguous Area in the range being counted. For example, in the Immediate window:

    ? range("a2:a3,a5:a7").cells.Count
    

    returns 5

    ? range("2:3,5:7").rows.Count
    

    returns 2

    ? range("2:3,5:7").areas(1).rows.Count
    

    returns 2

    ? range("2:3,5:7").areas(2).rows.Count
    

    returns 3

    As you can see, if you don’t specify an area the first one is returned.

    To get an answer for all areas loop through them:

    Sub CountRows()
    Dim i As Long
    Dim RowTotal As Long
    
    With ActiveSheet.Range("2:3,5:7")
        For i = 1 To .Areas.Count
            RowTotal = RowTotal + .Areas(i).Rows.Count
        Next i
    End With
    Debug.Print RowTotal
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pointless Dribble Okay This is another weird one from me, i want to thank
Using the following steps: (I have checked this similar post , which does not
This is a weird one. Long story short: wrote a usercontrol using AJAX. Used
another weird problem with the iPhone SDK here. I have a UITableView which contains
OK, this is Another Project Im Working ON. Its a Chat Client. and Using
I have a file like this: This is a sentence. This is another sentence.
I have an Apache Solr instance deployed in Glassfish and I am using this
I am using a WPF c# application. I have a user control which contains
I have a set of UIViews arranged in layers one over another. I've added
I have two node servers, one on port 5000 (call it Face) and another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.