Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Loop through sheets and get number of records per sheet

Hi all, i have a variable number of sheets in a workbook, with variable rows
of data in each sheet. Each sheet has a specific name. I need to loop through
all sheets and get the number of rows per sheet and store the number of rows
per sheet/name on a summary sheet.
e.g.

George 20
Les 150
Johan 60


Any help is as per normal much appreciated

--
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Loop through sheets and get number of records per sheet

Sub test()

Dim summ As Worksheet
Dim ws As Worksheet

Set summ = Worksheets.Add
summ.Name = "Summary"
Dim x As Integer

For Each ws In Worksheets
If ws.Name < "Summary" Then
summ.Range("a1").Offset(x, 1).Value =
ws.Cells.SpecialCells(xlCellTypeLastCell).Row
summ.Range("a1").Offset(x, 0).Value = ws.Name
x = x + 1
End If

Next ws

End Sub


"Les" wrote:

Hi all, i have a variable number of sheets in a workbook, with variable rows
of data in each sheet. Each sheet has a specific name. I need to loop through
all sheets and get the number of rows per sheet and store the number of rows
per sheet/name on a summary sheet.
e.g.

George 20
Les 150
Johan 60


Any help is as per normal much appreciated

--
Les

  #3   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Loop through sheets and get number of records per sheet

A Gentelman and a life saver....

Thanks so much Sam, much appreciated.
--
Les


"Sam Wilson" wrote:

Sub test()

Dim summ As Worksheet
Dim ws As Worksheet

Set summ = Worksheets.Add
summ.Name = "Summary"
Dim x As Integer

For Each ws In Worksheets
If ws.Name < "Summary" Then
summ.Range("a1").Offset(x, 1).Value =
ws.Cells.SpecialCells(xlCellTypeLastCell).Row
summ.Range("a1").Offset(x, 0).Value = ws.Name
x = x + 1
End If

Next ws

End Sub


"Les" wrote:

Hi all, i have a variable number of sheets in a workbook, with variable rows
of data in each sheet. Each sheet has a specific name. I need to loop through
all sheets and get the number of rows per sheet and store the number of rows
per sheet/name on a summary sheet.
e.g.

George 20
Les 150
Johan 60


Any help is as per normal much appreciated

--
Les

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Loop through sheets and get number of records per sheet

Hi
I've assumed your Summary Sheet is sheet1 and that your data is a
continuous range starting at A1 on each sheet. Should get you started.

Sub countrows()
Dim i As Integer, SheetCount As Integer
Dim RowCounts() As Variant
Application.Screenupdating = false
SheetCount = ActiveWorkbook.Worksheets.Count - 1 'don't count
SummarySheet
ReDim RowCounts(1 To SheetCount, 1 To 2)
For i = 2 To SheetCount + 1 'assume sheet1 is SummarySheet
RowCounts(i - 1, 1) = Worksheets(i).Name
RowCounts(i - 1, 2) =
Worksheets(i).Range("A1").CurrentRegion.Rows.Count
Next i
Worksheets("SummarySheet").Range("A2").Resize(Shee tCount,2).Value =
RowCounts
End Sub

regards
Paul

On May 20, 4:13*pm, Les wrote:
Hi all, i have a variable number of sheets in a workbook, with variable rows
of data in each sheet. Each sheet has a specific name. I need to loop through
all sheets and get the number of rows per sheet and store the number of rows
per sheet/name on a summary sheet.
e.g.

George * * 20
Les * * * * *150
Johan * * * 60

Any help is as per normal much appreciated

--
Les


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
Loop through sheets & filter main sheet using sheet name Les Excel Programming 4 May 20th 08 02:39 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
Number of Sheets (Full of Sheet) veryeavy Excel Discussion (Misc queries) 2 August 6th 07 12:37 PM
How to know the total number of records in the excel sheet kvenku[_36_] Excel Programming 3 August 27th 04 05:30 AM
Loop across Sheets and number of sheets Raj[_8_] Excel Programming 2 December 18th 03 09:18 AM


All times are GMT +1. The time now is 01:21 AM.

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"