+ Reply to Thread
Results 1 to 13 of 13

Macro or VBA to collect title and number of lines from each sheet in a workbook

  1. #1
    Registered User
    Join Date
    12-09-2017
    Location
    Ohio
    MS-Off Ver
    Excel 2013 (home/student)
    Posts
    60

    Macro or VBA to collect title and number of lines from each sheet in a workbook

    I have workbooks that contain multiple sheets (tabs). I would like to have a macro that creates a new sheet called "Inventory" that contains the name of each of the other sheets and the number of lines it contains. Can someone help with that, please?

    Russ

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this ‼


    As a beginner starter :

    PHP Code: 
    Sub Demo1()
      Const 
    "Inventory"
        
    Dim L&, R&
            
    Sheets.Count
            Application
    .ScreenUpdating False
        
    If Sheets(L).Name <> W Then
            Sheets
    .Add(, Sheets(L)).Name W
            L 
    1
        
    Else
            
    Sheets(L).UsedRange.Clear
        End 
    If
        For 
    1 To L 1
            Sheets
    (L).Cells(R1).Resize(, 2).Value = Array(Sheets(R).NameSheets(R).UsedRange.Rows.Count)
        
    Next
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 07-13-2018 at 12:15 PM. Reason: optimization …

  3. #3
    Registered User
    Join Date
    12-09-2017
    Location
    Ohio
    MS-Off Ver
    Excel 2013 (home/student)
    Posts
    60

    Re: Try this ‼

    Merci, Marc. Ça marche très bien!

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro or VBA to collect title and number of lines from each sheet in a workbook

    See next code, it works where ever rows
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro or VBA to collect title and number of lines from each sheet in a workbook

    Try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 07-13-2018 at 12:21 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool A variation …


    … with Inventory as first worksheet, as a beginner starter :

    PHP Code: 
    Sub Demo2()
      Const 
    "Inventory"
        
    Dim R&
            
    Application.ScreenUpdating False
            
    If Sheets(1).Name <> W Then Sheets.Add(Sheets(1)).Name Else Sheets(1).UsedRange.Clear
            Sheets
    (1).[A1:B1].Value = [{"Name","Rows count"}]
        For 
    2 To Sheets.Count
            Sheets
    (1).Cells(R1).Resize(, 2).Value = Array(Sheets(R).NameSheets(R).UsedRange.Rows.Count)
        
    Next
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 07-13-2018 at 12:24 PM. Reason: optimization …

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro or VBA to collect title and number of lines from each sheet in a workbook


    My bad, misread …

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro or VBA to collect title and number of lines from each sheet in a workbook

    An update to make things smarter
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Try this ‼

    Quote Originally Posted by OhioRuss View Post
    Merci, Marc. Ça marche très bien!
    Thanks for the rep' and your french words !

  10. #10
    Registered User
    Join Date
    12-09-2017
    Location
    Ohio
    MS-Off Ver
    Excel 2013 (home/student)
    Posts
    60

    Re: Macro or VBA to collect title and number of lines from each sheet in a workbook

    Thank you all. Marc's solution works, I haven't tried the others. Anyone care to comment on the relative merits?

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro or VBA to collect title and number of lines from each sheet in a workbook


    Salut PCI !

    Your code using CurrentRegion may return a wrong value if a worksheet has an empty row between two range of data …

    Another concern : Find will raise an error with an empty worksheet !
    Last edited by Marc L; 07-13-2018 at 06:14 PM. Reason: typo …

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro or VBA to collect title and number of lines from each sheet in a workbook

    @ OhioRuss - You're best situated to discuss the relative merits

  13. #13
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro or VBA to collect title and number of lines from each sheet in a workbook

    @Marc
    Yes, thank you for the comments which are setting some limits to others macros to.
    So here a remake:
    The first row can be every where
    Sheet can be empty
    Some empty rows may exist inside the used range: The empty row counted in the total
    It seems these specifications are out of the OP's needs it is just to close the loop
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need a macro to collect the existing size of columns of a particular sheet.
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-01-2016, 02:43 PM
  2. Report sheet collect all data in all workbook
    By Mamud in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2016, 07:26 PM
  3. Replies: 3
    Last Post: 09-27-2015, 02:15 PM
  4. Replies: 6
    Last Post: 12-16-2014, 09:27 AM
  5. Macro code editing to collect extra lines of Data
    By Cupragsw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2014, 08:22 AM
  6. Using a macro to sort and subtotal, but different number of lines on each sheet
    By kafarrell in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-21-2010, 05:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1