View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Lars-Åke Aspelin[_2_] Lars-Åke Aspelin[_2_] is offline
external usenet poster
 
Posts: 913
Default Visual Basic: Get row count of a sheet in Excel

On Mon, 6 Jul 2009 06:51:32 -0700 (PDT), Curious
wrote:

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").



Try this:

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

Hope this helps / Lars-Åke