Thanks a lot AB.
It's an elegant piece of code.
I had a problem with a "Subscript out of range" on this line.
I commented out that particular "If" statement and the code ran fine.
Sub ConsolidateData()
Dim ws As Worksheet, wsMaster As Worksheet, x, z, i As Long, ii&, k&
'Application.ScreenUpdating = 0
Set wsMaster = Sheets("Master")
x = Range("A1:E" & Cells.Find("*", , , , xlByRows, xlPrevious).Row) 'Load the data in to an array
ReDim z(1 To UBound(x) * Sheets.Count - 1, 1 To UBound(x, 2)) 'output array
For Each ws In Worksheets 'Loop through each sheet
If ws.Name <> wsMaster.Name Then ' if the sheet name is not "Master"
x = ws.Range("A1:E" & ws.Cells.Find("*", , , , xlByRows, xlPrevious).Row)
For i = 2 To UBound(x, 1) 'Loop through each array for each sheet at a time.
If Trim((x(i, 7))) = vbNullString Then
k = k + 1
For ii = 1 To UBound(x, 2) ' If the condition is true,loop through columns and copy data in to output array
z(k, ii) = x(i, ii)
Next
End If
Next i
End If
Next ws
With wsMaster
.UsedRange.Offset(1).ClearContents
.Range("A1").Resize(k, UBound(x, 2)) = z ' The adjusted array is copied back in to range.
.Columns.AutoFit
End With
End Sub
I was wondering what the intention was for this bit of code?
When I changed the number from 7 to 5, I received the value of the date in column five.
The problem was, it wouldn't output at all to the Master Worksheet.
I'd be interested in understanding the mechanics of this.
Thanks again.
Bookmarks