View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips[_3_] Bob Phillips[_3_] is offline
external usenet poster
 
Posts: 2,420
Default Visual Basic: Get row count of a sheet in Excel

You have to do something with that value

Sub MatchShortTermLimits()
myVal = Sheet2.UsedRange.Rows.Count
End Sub

or

Sub MatchShortTermLimits()
MsgBox Sheet2.UsedRange.Rows.Count
End Sub



--
__________________________________
HTH

Bob

"Curious" wrote in message
...
I have three sheets in the Excel, by default, they're called Sheet1,
Sheet2, and Sheet3.

I renamed the sheets to "MarketData", "LongTermLimits", and
"ShortTermLimits" respectively.

I want to create a VB (macro?) inside an Excel file as below:

Sub MatchShortTermLimits()
Sheet2.UsedRange.Rows.Count
End Sub

It gives me an error, "Compile error: Invalid use of property"

I changed the code to:

Sub MatchShortTermLimits()
LongTermLimits.UsedRange.Rows.Count
End Sub

It then complains "Object required"

Any advice on how to get this fixed? I only want to get the row count
of Sheet2 (renamed to "LongTermLimits").