Consulting

Results 1 to 9 of 9

Thread: Count Half of the Visible Rows

  1. #1
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location

    Count Half of the Visible Rows

    Hi,

    The following code counts the visible rows. For example if 5 rows are visible out of 10 rows, it says 5 of 10 records.
    Any help to change the code so that it counts half of the visible rows would be kindly appreciated.For example if 2 rows are visible the display message would be as 1 of 10 records.

    If 4 rows are visible the message would display as 2 rows.
     Sub CountVisRows()
    Dim rng As RangeSet rng = ActiveSheet.AutoFilter.Range 
    MsgBox rng.Columns(1). _   
    SpecialCells(xlCellTypeVisible).Count - 1 _   & " of " & rng _   .Rows.Count - 1 & " Records" 
    End Sub
    Best Regards,
    adamsm

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why?

    [vba]

    Sub CountVisRows()
    Dim rng As Range
    Set rng = ActiveSheet.AutoFilter.Range
    MsgBox (rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1) \ 2 & _
    " of " & rng.Rows.Count - 1 & " Records"
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    [VBA]MsgBox (rng.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1) / 2 & " of " & rng.Rows.Count - 1 & " Records"[/VBA]?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Thanks for the help p45cal & xld. That was what I needed. I do really appreciate it.

    By the way in reply to xld I must say according to my workbook the suggested codes work better.
    Best Regards,
    adamsm

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Works better? The answer is just wrong.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Why is the answer wrong?
    Best Regards,
    adamsm

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    As you said youreslef ... If 4 rows are visible the message would display as 2 rows.

    I may not know much but I know that is not accurate.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    That's because I want to count only half of the visible rows.
    Best Regards,
    adamsm

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I know that, I just cannot see why. Butwe are going round in circles, and it is not important, so let's drop it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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