Here you go.. this works on that Workbook as well..
Just uses a different method to find the last used column..
Private Sub CommandButton1_Click()
Dim x, y, strFile As String, i As Long, ii As Long, iii As Long, j As Long, LR As Long, LC As Long
Dim ws As Worksheet, wb As Workbook
Application.DisplayAlerts = False
'User Selects desired File
strFile = Application.GetOpenFilename("Excel Files,*.xls*")
If strFile = "False" Then Exit Sub
'Open (in background) the Workbook
Set wb = GetObject(strFile)
With GetObject(strFile)
For Each ws In wb.Sheets
LC = .Sheets(ws.Name).Cells.Find("*", SearchOrder:=xlByColumns, LookIn:=xlValues, SearchDirection:=xlPrevious).Column
LR = .Sheets(ws.Name).Range("Q" & Rows.Count).End(xlUp).Row
x = .Sheets(ws.Name).Range(.Sheets(ws.Name).Cells(2, 1), .Sheets(ws.Name).Cells(LR, LC))
ReDim y(Application.CountIfs(.Sheets(ws.Name).Range(.Sheets(ws.Name).Cells(3, 6), .Sheets(ws.Name).Cells(LR, LC)), "<>0") - 1, 1 To 7)
'Build New Array
For i = 6 To LC
y(j, 1) = Application.Index(x, 1, i)
For ii = 2 To UBound(x)
If x(ii, i) <> "0" Then
For iii = 2 To 6
y(j, iii) = x(ii, iii - 1)
Next iii
y(j, 7) = x(ii, i)
j = j + 1
End If
Next ii
Next i
' Write new array to sheet
Sheets("Main").Range("A" & Sheets("Main").Range("B" & Rows.Count).End(xlUp).Row).Offset(1).Resize(UBound(y) + 1, 7).Value = y
j = 0
Next ws
.Close
End With
Cleanup:
Set fldr = Nothing
Application.DisplayAlerts = True
End Sub
Bookmarks