Results 1 to 9 of 9

Thread: Always ON Row Count

  1. #1
    Acolyte oskar's Avatar
    Join Date
    May 2013
    Location
    Montreal, Canada
    Posts
    24
    Articles
    0
    Excel Version
    Office 2013

    Always ON Row Count



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Following a VBA lesson from the web I made a contacts DB and now I have in sheet1 my ActiveX userform and in sheet2 I have my dynamic range DB (a typical address layout with 151 rows).

    I would like to but a box in the userform (cmd button, or txtbox or what is appropriate) to indicate the number of used rows in sheet2. In other words this box will tell me the total number of contacts since each row is one contact

    I donít want to press any button to get the number. The number will always be on and change as I add / delete contacts.

    This is a hobby project and I have a basic knowledge of VBA (Excel 2013, student)

    Thank you

  2. #2
    Conjurer Roger Govier's Avatar
    Join Date
    Mar 2011
    Location
    Located near Abergavenny, South Wales, UK
    Posts
    113
    Articles
    0
    Hi oskar

    You would use something like
    Me.Label1.Caption = "Count: " & WorksheetFunction.Counta(Sheets("Sheet2").Range("A:A"))
    Regards

    Roger Govier
    Microsoft Excel MVP
    http://www.technology4u.co.uk

  3. #3
    Super Moderator Bob Phillips's Avatar
    Join Date
    Mar 2011
    Posts
    1,829
    Articles
    0
    Excel Version
    O365
    If the first row is headings (it should be), you will need to subtract 1 from the count as Roger gave it.

  4. #4
    Conjurer snb's Avatar
    Join Date
    May 2013
    Posts
    376
    Articles
    0
    Excel Version
    2020
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Column = 1 Then Application.StatusBar = Columns(1).SpecialCells(2).Count-1
    End Sub

  5. #5
    Acolyte oskar's Avatar
    Join Date
    May 2013
    Location
    Montreal, Canada
    Posts
    24
    Articles
    0
    Excel Version
    Office 2013
    I made a Label and a control button and it works nicely when I click the control button.

    Is there a way to have the Label indicating the total number of rows without clicking a control?

  6. #6
    Conjurer snb's Avatar
    Join Date
    May 2013
    Posts
    376
    Articles
    0
    Excel Version
    2020
    I gave you that answer.

  7. #7
    Acolyte oskar's Avatar
    Join Date
    May 2013
    Location
    Montreal, Canada
    Posts
    24
    Articles
    0
    Excel Version
    Office 2013
    Sorry snb I'm a beginner, and where do I put this code

  8. #8
    Acolyte oskar's Avatar
    Join Date
    May 2013
    Location
    Montreal, Canada
    Posts
    24
    Articles
    0
    Excel Version
    Office 2013
    When I put the code in post #2 in a blank workbook and fill out some rows it works but when I put the same code in my contacts db (after I change the sheet ref) I get: error 9, subscript out of range.

    I canít figure this out, any ideas what I do wrong?

  9. #9
    Acolyte oskar's Avatar
    Join Date
    May 2013
    Location
    Montreal, Canada
    Posts
    24
    Articles
    0
    Excel Version
    Office 2013
    This worked for me

    Code:
    Private Sub commandButton21_click()
     Dim Count As Integer
        Range("b9").Select
            Range(Selection, Selection.End(xlDown)).Select
    Sheet1.Label218.Caption = "" & Selection.Cells.Count
        Range("b9").Select
    End Sub

Posting Permissions

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