Hi ...
I have multiple workbooks saved in a folder and the code below seems to only work for my first file. However, I need it to work for all the files in the folder but can't seem to see where I have gone wrong.
I have multiple workbooks saved in a folder and the code below seems to only work for my first file. However, I need it to work for all the files in the folder but can't seem to see where I have gone wrong.
Code:
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Dim shtcopy As Worksheet
Dim shtfinal As Worksheet
Dim LastRow As Long
DataRow = 3
OutRow = 2
Role1Col = 13
Const strPath As String = "filename"
ChDir strPath
strExtension = Dir("*.xls*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
LastRow = .Sheets("Actual Hours").Cells(10000, 1).End(xlUp).Row
Do Until .Sheets("Sheet1").Cells(DataRow, 1) = ""
OutStart = OutRow
RoleCol = Role1Col
Do Until .Sheets("Sheet1").Cells(2, RoleCol) = ""
If .Sheets("Sheet1").Cells(DataRow, RoleCol) > 0 Then
.Sheets("Sheet4").Cells(OutRow, Role1Col) = .Sheets("Sheet1").Cells(1, Role1Col + VBA.Int((RoleCol - Role1Col) / 3) * 3)
.Sheets("Sheet4").Cells(OutRow, Role1Col + 1) = .Sheets("Sheet1").Cells(2, RoleCol)
.Sheets("Sheet4").Cells(OutRow, Role1Col + 2) = .Sheets("Sheet1").Cells(DataRow, RoleCol)
OutRow = OutRow + 1
End If
RoleCol = RoleCol + 1
Loop
If OutStart <> OutRow Then
.Sheets("Sheet1").Range(.Sheets("Sheet1").Cells(DataRow, 1), .Sheets("Sheet1").Cells(DataRow, Role1Col - 1)).Copy .Sheets("Sheet4").Range(.Sheets("Sheet4").Cells(OutStart, 1), Sheets("Sheet4").Cells(OutRow - 1, Role1Col - 1))
End If
DataRow = DataRow + 1
Loop
.Close savechanges:=True
End With
strExtension = Dir
Loop