I am lost and have tried to find this specific issue on multiple forums and cannot seem to piece it together. Very quick question hopefully. This code is meant to:
- Search for last cell that contains data in 5 worksheets. It should search other than Column 'A' or 'B' for data, as these may or may not be blank.
- repeat for all 5 sheets in array
- Paste all data from 5 sheets in source workbook on 'Sheet 4' one after another
The problem I have is that maybe usedrange.copy is copying all data from the 5 workbooks strangely. It does not seem to copy ALL of the data (maybe counting column A to find last used row and copying based on that?).
Is there a different way of achieving what I am needing to do? I thought it would be easier because it is just copying all data from the 5 sheets and pasting in a different wkbk... but... nay. Any help is greatly appreciated.
Sub Notes2()
'Last row in column
Dim WS As Worksheet, shAry As Variant, i As Long
Dim AOFF As Range
Dim rOWIS As Integer
Dim wb As Workbook, wb2 As Workbook
Dim vFile As Variant
'Set source workbook
Set wb = ActiveWorkbook
Set WS = Worksheets("Sheet 4")
With WS
Set LastCell = .Cells(.Rows.Count, "A").End(xlUp)
LastCellRowNumber = LastCell.Row + 1
End With
'Open the target workbook
vFile = Application.GetOpenFilename("Excel-files,*.xlsx", _
1, "Select File To Open", , False)
'if the user didn't select a file, exit sub
If TypeName(vFile) = "Boolean" Then Exit Sub
Application.ScreenUpdating = False
Set wb2 = Workbooks.Open(vFile)
With wb2
shAry = Array(.Sheets("Week 1"), .Sheets("Week 2"), .Sheets("Week 3"), .Sheets("Week 4"), .Sheets("Over 30"))
End With
For i = LBound(shAry) To UBound(shAry)
shAry(i).UsedRange.Copy
wb.Activate
WS.Cells(Rows.Count, 3).End(xlUp).End(xlUp)(2).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Next
Application.ScreenUpdating = True
'Close
wb2.Close False
End Sub