OBJECTIVE
Copy a group of rows from multiple worksheets and insert into a CONSOLIDATED worksheet.
APPROACH
- Go to
CONSOLIDATEDworksheet and remove pre-existing information - Use an IF statement to find relevant worksheets where we intend to pull data from
- Copy relevant columns and rows on each worksheet (e.g A6:G(lastrow))
- Append copied data to
CONSOLIDATEDworksheet !!!ERROR
(ugly) CODE
Sub consolidateConvert()
Dim ws As Worksheet
'Set CONSOLIDATED as the active worksheet
Application.ScreenUpdating = False
Sheets("CONSOLIDATED").Activate
'Clear previous content from active sheet
ActiveSheet.Range("A1:G10000").ClearContents
'Iterate through workbooks, except for CONSOLIDATED, TITLE, and PIVOT worksheets
For Each ws In Worksheets
If ws.Name <> "CONSOLIDATED" And ws.Name <> "PIVOT" And ws.Name <> "TITLE" _
And ws.Name <> "APPENDIX - CURRENCY CONVERTER" And ws.Name <> "MACRO" Then
'Find last row of current worksheet
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row
'Copy current worksheet cells and insert into CONSOLIDATED worksheet
ws.Range("A6:G" & lastRow).Copy
ActiveSheet.Range("A2").End(xlUp).Insert shift:=xlDown
End If
Next ws
Call currencyConvert
Call addHeaders
currencyConvert is a function that isn't relevant to this particular question. However, I've added addHeaders function below:
Sub addHeaders()
Dim ws As Worksheet
Dim headers() As Variant
'Define worksheet and desired headers
Set ws = ThisWorkbook.Sheets("CONSOLIDATED")
headers() = Array("Fiscal Year", "Month", "Fiscal Month", "Month Year", "Unit", "Project", "Local Expense", "Base Expense")
'Insert row for header placement
Rows(1).Insert shift:=xlShiftDown
'Insert headers
With ws
For i = LBound(headers()) To UBound(headers())
.Cells(1, 1 + i).Value = headers(i)
Next i
End With
End Sub
OUTPUT
Below is a screenshot of the unexpected output. Rows 2-7 are unexpected and include some random text strings that aren't present anywhere else within the workbook. Strings may be some weird inheritance issue in VBA but not quite sure (hence the question(s) below).
QUESTIONS
- As mentioned before, Rows 2-7 are added unintentionally and are accompanied with some weird strings. Does anyone have any insight on why ~6 rows are being added (when only 1 should be added - see
addHeaders())? Additionally, what is the origin of the unintended strings ("CatalogNickname", "EnvironmentKey", etc.)?

ws.Range("A6:G" & lastRow).Copy ActiveSheet.Range("A2").End(xlUp).Insert shift:=xlDown??ws.Range("A6:G" & lastRow).Copy. DoeslastRowever return a value of<6? When I put? Range("A6:G1").Addressin the immediate window it returns$A$1:$G$6.