Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,388
Default Count Number of Rows in a Workbook

Hello Everyone,

Can anyone tell me how to run a macro that will:

* open a workbook
* count the number of rows
* write this number in the first workbook

thanks!
Dave
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Count Number of Rows in a Workbook

Dave,

Try something like the following. Change the workbook, worksheet, and range
references in the lines marked with '<<<< to the appropriate values.

Sub AAA()
Dim SaveWB As Workbook
Dim WB As Workbook
Dim WS As Worksheet
Dim Rng As Range
Dim NumRows As Long

Set SaveWB = ActiveWorkbook
Set WB = Workbooks.Open("C:\Test\Book1.xls") '<<<< CHANGE
Set WS = WB.Worksheets("Sheet1") '<<<< CHANGE
With WS.UsedRange
NumRows = .Cells(.Cells.Count).Row - .Cells(1, 1).Row + 1
End With
WB.Close savechanges:=False
SaveWB.Worksheets("Sheet1").Range("A1").Value = NumRows '<<<< CHANGE
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Dave" wrote in message
...
Hello Everyone,

Can anyone tell me how to run a macro that will:

* open a workbook
* count the number of rows
* write this number in the first workbook

thanks!
Dave


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
COUNT NUMBER OF ROWS Keep It Simple Stupid Excel Worksheet Functions 2 February 9th 07 06:54 PM
Count how many Rows ago a particular number was hit rhhince Excel Worksheet Functions 1 January 13th 07 09:06 PM
Count number of rows, where non relevant rows are hidden Pieter Excel Discussion (Misc queries) 2 November 8th 06 12:24 PM
Count rows and insert number to count them. Mex Excel Discussion (Misc queries) 6 August 23rd 06 02:29 AM
Count the number of worksheets in a workbook Vincdc Excel Discussion (Misc queries) 7 January 17th 05 11:57 PM


All times are GMT +1. The time now is 01:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"