Hi Guys,
I have the below code, which looks through a folder for files and copies the data into my open workbook. I need the code to look for filenames only containing a string of ABC, and if the filename contains anything else, then X (The sheet to copy) would be 1 to 2 (Instead of 3 to 3)... Anyhelp?
Thanks
I have the below code, which looks through a folder for files and copies the data into my open workbook. I need the code to look for filenames only containing a string of ABC, and if the filename contains anything else, then X (The sheet to copy) would be 1 to 2 (Instead of 3 to 3)... Anyhelp?
Thanks
VBA Code:
Do While MyFile <> ""
Set wkbSource = Workbooks.Open(Filename:=MyFolder & "\" & MyFile)
For x = 3 To 3
If WorksheetFunction.CountA(Sheets(x).Cells) <> 0 Then
With Sheets(x)
LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End With
With Surveys
Sheets(x).UsedRange.Copy .Cells(.Rows.Count, "B").End(xlUp).Offset(2, 0)
.Cells(.Rows.Count, "A").End(xlUp).Offset(2, 0).Resize(LastRow) = wkbSource.Name
End With
End If
Next x
MyFile = Dir
wkbSource.Close False
Loop