+ Reply to Thread
Results 1 to 9 of 9

Count Records Problem

Hybrid View

  1. #1
    Registered User
    Join Date
    02-17-2012
    Location
    Vaslui,Romania
    MS-Off Ver
    Excel 2007
    Posts
    4

    Count Records Problem

    I have a couple of excel worksheets all in the same formats. And I have to extract how many values of each kind i have. I apply a filter and after that I try to get the number of records. But I can't find a reliable method. Any ideas could help.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Count Records Problem

    Could you post an example workbook showing us what you're trying to do?

  3. #3
    Registered User
    Join Date
    02-17-2012
    Location
    Vaslui,Romania
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Count Records Problem

    Can't upload from where I am now.
    But for example:in column C I have various types of colors. And I try to find out how many of a specific color I have. If I search one that has no appereance will still return 1.
              ActiveSheet.Range("A1:C1").AutoFilter Field:=3, Criteria1:= _
                    "=white", Operator:=xlOr
                Set rng = ActiveSheet.Range("A2:A" & ActiveSheet.Range("A65536").End(xlUp).Row)
                white= rng.SpecialCells(xlCellTypeVisible).Count
    I would expect an error or smth.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Count Records Problem

    Can't you just use:

    white=WorksheetFunction.CountIf(ActiveSheet.Range("A:A"),"white")

  5. #5
    Registered User
    Join Date
    02-17-2012
    Location
    Vaslui,Romania
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Count Records Problem

    It would work very smooth but for color "blue" for example I need to copy the results in another worksheet so this is why I choosed the filtering way.

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Count Records Problem

    How many rows of data will you have to copy at once? Personally I'd go with a .Find within a loop to match and copy each row - I just plain don't like using filters.

  7. #7
    Registered User
    Join Date
    02-17-2012
    Location
    Vaslui,Romania
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Count Records Problem

    Well..that's the problem. I have smth like 25 worksheets with 1000 to 3000 lines. And both the number of worksheets and lines can increase in time.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Count Records Problem

    you can use advancedfilter.
    Check the number of unique items first:
    After that you can use advancedfilter to split the data in separate sheets

    sub snb()
      sheets(1).columns(3).advancedfilter xlfiltercopy,,sheets(1).cells(1,20),true
    
      sn=sheets(1).columns(20).specialcells(2)
      sheets(1).cells(1,20).offset(2).reszie(ubound(sn).clearcontents
    
      for j=2 to ubound(sn)
        sheets(1).cells(2,20)=sn(j,1)
        sheets(1).cells(1).currentregion.advancedfilter xlfiltercopy,cheets(1).cells(1,20).currentregion,sheets(2).cells(1)
      next
    End Sub



  9. #9
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Count Records Problem

    Are you feeling OK, snb? Not only is your code *way* more than 1 line, but you've also added a whole new 'reszie' method for the range object

    Edited to add: Oh, and a 'cheets' object. Who are you, and where's the real snb?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1