Hi Everyone,
I currently have some code that I would like changed, but I'm not too sure on how exactly to fix it. Here is the code:
Dim oWbk As Workbook
Dim uRng As Range
Dim rToCopy As Range
Dim rNextCl As Range
Dim lCount As Long
Dim bHeaders As Boolean
Dim sFil As String
Dim sPath As String
Dim objFile As Object
Dim objFso As New FileSystemObject
With Application
.DisplayAlerts = False
.EnableEvents = False
sPath = Sheets("Info").Range("A15").Value
Set flsFolder = objFso.GetFolder(sPath & "\")
For Each objFile In flsFolder.Files
sFil = objFile.Name
If InStr(1, Right(sFil, Len(sFil) - InStr(1, sFil, ".")), "xl") > 0 Then
With ThisWorkbook.Sheets("Combined")
Set uRng = .UsedRange
If uRng.Cells.Count = 0 Then
bHeaders = False
Else
bHeaders = True
End If
Set oWbk = Workbooks.Open(objFile)
Set rToCopy = oWbk.ActiveSheet.UsedRange
If Not bHeaders Then
Set rNextCl = .Cells(1, 2)
bHeaders = True
Else
Set rNextCl = .Cells(.Rows.Count, 2).End(xlUp).Offset(1, 0)
Set rToCopy = rToCopy.Offset(6, 0).Resize(rToCopy.Rows.Count - 1, _
rToCopy.Columns.Count)
End If
rToCopy.Copy
rNextCl.PasteSpecial xlPasteValues
rNextCl.Offset(0, -1).Value = oWbk.ActiveSheet.Range("A4").Value
.Cells(Rows.Count, 1).End(xlUp).AutoFill Destination:=.Range(.Cells(Rows.Count, 1).End(xlUp), .Cells(.Cells(Rows.Count, "C").End(xlUp).row, 1)), Type:=xlFillCopy
oWbk.Close False
End With
End If
Next
exithandler:
.DisplayAlerts = True
.EnableEvents = True
End With
As of right now, this code takes files and combines the worksheets into 1 worksheet. The folder path of these files is pasted in Cell A15 and then the macro picks up any file with "xl" in the file extension. What I'd like is for the user to be able to paste the filename in Cell A16 instead.
Could someone please take a look and see if they can make it so that the macro picks up the file where the folder path is in A15 and the filename is in A16?
Thanks in advance!
Bookmarks