Consulting

Results 1 to 7 of 7

Thread: VBA MACRO CODE FOR getting sheet names at once in multiple sheets

  1. #1
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location

    VBA MACRO CODE FOR getting sheet names at once in multiple sheets

    Hello Everyone,

    I would like to get the sheet name in the first column of all the sheets. (highlighted one...) automatically at once by one click.
    please do the needful.
    Please provide me some macro code for this...


    I have attached the excel file where i did manually for your easy understanding and reference.


    Thank you...
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Public Sub Insertname()
    Dim ws As Worksheet
    Dim lastrow As Long
    
        For Each ws In ThisWorkbook.Worksheets
        
            lastrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
            ws.Columns(1).Insert
            ws.Range("A1").Resize(lastrow).Value = ws.Name
            ws.Columns(1).AutoFit
        Next ws
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location
    Quote Originally Posted by xld View Post
    Public Sub Insertname()
    Dim ws As Worksheet
    Dim lastrow As Long
    
    End Sub
    Hello xld,
    The code is awesome... really it works beautifully.... Thank you so much...
    Thank you for spending your valuable time in helping me...
    I have got a small doubt, now i am getting the tabs name, instead if i want to get my file name, like in which part of code i need to modify. is it possible??

    Thank you...

    Regards,
    Dharani.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Change

     ws.Range("A1").Resize(lastrow).Value = ws.Name
    to

     ws.Range("A1").Resize(lastrow).Value = ws.Parent.Name
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Sub M_snb()
        Sheets(1).Cells(1) = ThisWorkbook.FullName
        Sheets.FillAcrossSheets sheets(1).Cells(1)
    End Sub

  6. #6
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location
    Quote Originally Posted by xld View Post
    Change

     ws.Range("A1").Resize(lastrow).Value = ws.Name
    to

     ws.Range("A1").Resize(lastrow).Value = ws.Parent.Name
    Thanks a lot xld... the code is awesome... thank you so much for spending your valuable time in helping me...

    Regards,
    Dharani.

  7. #7
    Quote Originally Posted by snb View Post
    FillAcrossSheets
    That is what I love about forums, you learn new stuff every time!
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

Posting Permissions

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