Link to home
Start Free TrialLog in
Avatar of Rayne
RayneFlag for United States of America

asked on

Row count Excel

Hello,


Sub countRows()
ActiveSheet.Range("C3").Select
Dim s As Long
'MsgBox ("Rows to end: " & Selection.End(xlDown).Row - (Selection.Row - 1))
s = Selection.End(xlDown).Row - (Selection.Row - 1)
MsgBox "count: " & s
TextBox1.Text = s
End Sub

I am not sure what I am missing….
Avatar of Rayne
Rayne
Flag of United States of America image

ASKER

I am trying to count the number of rows in a worksheet and then feed that in a textbox for display to users
Avatar of Rayne

ASKER

.this is giving errors..
This perhaps?
Sub countRows()
    
Dim s As Long

s = Range("C3").End(xlDown).Row - 2
MsgBox "count: " & s
UserForm1.TextBox1.Text = s

End Sub

Open in new window

I've done it this  way
------------------------------------
....

b = Range("C3", Range("C" & Rows.Count).End(xlUp)).Value
s = UBound(b, 1)

MsgBox "count: " & s
UserForm1.TextBox1.Text = s

......
However, thinking about it, you would probably need to put this code in the userform module.
Avatar of Rayne

ASKER

I am still getting a object required error
try this

ActiveSheet.TextBox1.Value = s
Avatar of Rayne

ASKER

Thank you Steve - Awesome that works but there is one issue – can you get it to refresh as I delete or add more row. For example if user adds new rows or delete row, the text box value display refreshes automatically?? Is that achievable? So in essence no need for the test button…
Avatar of Rayne

ASKER

I increased the points because I really need to make this module work nice :)
ASKER CERTIFIED SOLUTION
Avatar of stevefriese
stevefriese
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rayne

ASKER

Perfect as it can get. Thank you Steve, that is a life saver :)
Avatar of Rayne

ASKER

Perfect