Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Excel - Slight edit of the macro below should do the trick! Add filename to cell A1 upon merge.

I have a macro below that will merge all the xls files in a directory
into one excel file. What I want is a slight addition to my macro to
bring into cell A1 the filename of each so that I can show a clear
distinction between the files being merged into one sheet.

Can someone help with this small change?

Kind Regards,

Stuart

Sub CombineFiles()
Dim TargetSht As Worksheet
Dim i As Integer
Dim wks As Worksheet


Application.ScreenUpdating = False


Set TargetSht = ThisWorkbook.ActiveSheet


With Application.FileSearch
.NewSearch
.LookIn = "I:\CDF Test\excel\test"
.SearchSubFolders = False
.Filename = "*.xls"
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s)
found."
For i = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(i)
For Each wks In ActiveWorkbook.Worksheets
wks.UsedRange.Copy Destination:= _
TargetSht.Cells(Rows.Count, 1).End(xlUp).Offset(1,
0)


Next wks
ActiveWorkbook.Close False
Next i
Else
MsgBox "There were no files found."
End If
End With
Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel - Slight edit of the macro below should do the trick! Add filename to cell A1 upon merge.


"Stuart" ha scritto nel messaggio
oups.com...
I have a macro below that will merge all the xls files in a directory
into one excel file. What I want is a slight addition to my macro to
bring into cell A1 the filename of each so that I can show a clear
distinction between the files being merged into one sheet.

Can someone help with this small change?


I'm not sure if I've understood correctly but you can try to insert this
line in the routine:

............
For i = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(i)

'****************START NEW LINE***********************
TargetSht.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0) = "--
" & .FoundFiles(i) & " <--"
'****************END NEW LINE***********************
For Each wks In ActiveWorkbook.Worksheets
..... ......



Bye

FM




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
edit the cell contents command in Excel 2007 macro Safia Excel Worksheet Functions 1 March 4th 10 06:48 PM
How can I edit cell contents with a macro in Excel? Mind the gaps! Excel Discussion (Misc queries) 2 March 23rd 05 08:51 PM
How can I edit cell contents with a macro in Excel? NotAnExpert Excel Discussion (Misc queries) 1 March 23rd 05 01:17 AM
Excel Macro to edit and delete one character in a cell David Excel Programming 5 December 8th 04 12:02 PM
Another avoid the loop trick request - on fast fill (Maybe an Alan trick) [email protected] Excel Programming 2 October 6th 04 07:13 PM


All times are GMT +1. The time now is 04:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"