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
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]
The sheet name should be copied to column M for all rows.
Thanks,
Swathi
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]
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]
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]
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks