+ Reply to Thread
Results 1 to 6 of 6

Thread: Tab Name as column Name

  1. #1
    Registered User
    Join Date
    10-04-2011
    Location
    zurich
    MS-Off Ver
    Excel 2003
    Posts
    24

    Tab Name as column Name

    Hi All,

    I have some Excel sheets in E:\DLB folder, for some Excel files there are two worksheets for some three worksheets and for some four worksheets. The number of worksheets are not fixed. I want to insert the worksheet name as column data for all the worksheets present.

    Please suggest me a logic, how can I do this.

    Thanks,
    Swathi
    Attached Files Attached Files

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,382

    Re: Tab Name as column Name

    In which column should the sheet name be copied? All cells or just one particular cell of the column?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    10-04-2011
    Location
    zurich
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Tab Name as column Name

    The sheet name should be copied to column M for all rows.

    Thanks,
    Swathi

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,382

    Re: Tab Name as column Name

    Ok, i will have something for you shortly.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,382

    Re: Tab Name as column Name

    Use this code -
    Option Explicit
    
    Dim CurrentFileName As String
    Dim myPath As String
    Dim lrow As Long
    Dim i As Long
    
    Sub cons_data()
    
    'The folder containing the files to be recap'd
    myPath = "D:\Test" 'INPUT YOUR PATH HERE
    
    'Finds the name of the first file of type .xls in the current directory
    CurrentFileName = Dir(myPath & "\*.xls")
    
    'Create a workbook for the recap report
    
    Do
        Workbooks.Open (myPath & "\" & CurrentFileName)
        For i = 1 To Workbooks(CurrentFileName).Worksheets.Count
            With Workbooks(CurrentFileName).Worksheets(i)
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                .Range("M1:M" & lrow).Value = .Name
            End With
        Next i
           
        Workbooks(CurrentFileName).Close (True)
        
    'Calling DIR w/o argument finds the next .xlsx file within the current directory.
    CurrentFileName = Dir()
    Loop While CurrentFileName <> ""
    
    End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  6. #6
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,382

    Re: Tab Name as column Name

    Got posted twice so removed the code.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0