I have found this great code someone had wrote that when ran, allows you to select certain files in the same directory and run the same macro/procedure on each of them - in my case is just a straight copy and paste. The problem I am having with it I believe is related to the targeted 'paste sheet' or master sheet.
-on the master sheet when all of the data is cleared out and I run the below, the 1st source file runs fine, but after that it overwrites itself on the 2nd source file and > instead of a (xlDown) type of procedure.
- if I have anything <>""" in the first row of data input (in my case its cell "B2" because I have headers), then the below works exactly what I am expecting.
I am not sure why this is; it could be because I have the master sheet in a Table format?
--hopefully I have explained this clear enough
-on the master sheet when all of the data is cleared out and I run the below, the 1st source file runs fine, but after that it overwrites itself on the 2nd source file and > instead of a (xlDown) type of procedure.
- if I have anything <>""" in the first row of data input (in my case its cell "B2" because I have headers), then the below works exactly what I am expecting.
I am not sure why this is; it could be because I have the master sheet in a Table format?
--hopefully I have explained this clear enough
Code:
Sub SelectOpenCopy()
Dim vaFiles As Variant
Dim i As Long
Dim wb As Workbook
Dim File_Path As String
File_Path = Range("File_Path").Value
vaFiles = Application.GetOpenFilename("Excel Files (*.xlsx), *.xlsx", _
Title:="Select files", MultiSelect:=True)
If IsArray(vaFiles) Then
For i = LBound(vaFiles) To UBound(vaFiles)
Set wb = Workbooks.Open(filename:=vaFiles(i))
''BSQUAD code
wb.Worksheets("FI Medical").Select
Range("A2:AB2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("" & File_Path & "").Activate
Sheet33.Select
Range("B1").End(xlDown).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths
Selection.PasteSpecial Paste:=xlPasteValues
wb.Application.CutCopyMode = False
wb.Close savechanges:=False
''BSQUAD code
Next i
End If
Sheet33.Range("B1").Select
End Sub