tags:

views:

305

answers:

1

I have the following vba: Data is all text, Rows A - J with column headers on every sheet are the same Data is sql queries all with "top 1000" 4 sheets (sheet1, sheet2, sheet3, Master)

sheet 1: 100 rows sheet 2: 34 rows sheet 3: 900 rows Master: merged data from 3 sheets

PROBLEM: Sheet3 only copies 84 rows specifically however adding more rows to other sheets will copy over to Master. Only sheet3 will not copy more than 84 rows.

' Step 1: Clear master before updating ' Step 2 : Loop through the regional sheets

Sub Consolidate()

Dim cell            As Range
Dim wks             As Worksheet

Sheets("Master").Range("A2:Z65536").ClearContents

For Each wks In ThisWorkbook.Worksheets
    If wks.Name <> "Master" And wks.Range("A2") <> "" Then

        For Each cell In wks.Range(wks.Range("A2"), wks.Range("A2").End(xlDown))
             cell.EntireRow.Copy Destination:=Worksheets("Master").Range("A65536").End(xlUp).Offset(1, 0)
        Next cell
    End If
Next wks

End Sub

Thanks

+1  A: 

Is the data starting in Range (A2) always populated?

The For Each cell In wks.Range(wks.Range("A2"), wks.Range("A2").End(xlDown)) will start from A2 and go to the last populated cell before a blank/empty cell.

Cynicszm
I'm a bit new to vba, but if I understand correctly the Range("A2") is never null or empty. there's always data from A2:Jxxxx which needs to be populated into the master.Thanks
Ehsan
I would check the data on sheet 3 to be sure that Range A2 onwards is always populated, can't see anything else that would cause the problem from your vba...especially if it works for other sheets
Cynicszm
Yea that's interesting, sheet3 is populated from A2:J903. I thought maybe there's a size issue where the Range object or Worksheet object can't hold more than a certain number of rows. But obviously that's dumb and other sheets work fine with more data. I guess it's one of those mysteries because I can't think of anything else at this point. Thanks for the help tho.
Ehsan
there was an empty cell at A843...guess I missed it. That was the solution. Thanks Cynicszm
Ehsan