VBA - Copy Paste rows (including Blanks) + Offset Question

xceln00b

New Member
Joined
Aug 30, 2016
Messages
5
Frustrated with this problem...

I have a workbook with multiple sheets. I want to take the value of Cell A2 from every sheet (including Blank cells), and Paste it into Cell A2 of this "Master" sheet and offset the row by 1 and continue pasting row after row.


Code:
Sub CopyIt()
Dim ws As Worksheet
Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> "Master" Then
            ws.Range("A2").Copy
            Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Offset(1,0).PasteSpecial xlPasteValues
        End If
    Next
Application.ScreenUpdating = True
End Sub

The problem I have is that the above code ignores blank cells in the sheets. I think the problem is the .End(xlUp) property. But how do I modify the code so that it pastes the value starting in Cell A2 (including blanks) and offsets by 1 row down?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try:
Code:
Sub CopyIt()
Dim ws As Worksheet, Ct As Long
Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> "Master" Then
            Ct = Ct + 1
            ws.Range("A2").Copy
            Sheets("Master").Range("A1").Offset(Ct).PasteSpecial xlPasteValues
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
For anyone looking for the whole code:
First, the program adds a new sheet called "Master", then it scans all the sheets from the workbook and copies the Cell A2 (regardless of whether the cell is blank or not) from every sheet that's not "Master" and pastes it into Cell A2, A3, A4... of the Master sheet and so on.

Code:
Sub CopyIt()
 
Dim ws As Worksheet, x As Long
 
Application.ScreenUpdating = False
 
Worksheets.Add.Name = "Master"
Sheets("Master").Range("A1").Value = "Associate Name"
 
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> "Master" Then
            x = x + 1
            ws.Range("A2").Copy
            Sheets("Master").Range("A1").Offset(x).PasteSpecial xlPasteValues
           
        End If
    Next
 
Columns.AutoFit
 
Application.ScreenUpdating = True
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,548
Messages
6,125,464
Members
449,229
Latest member
doherty22

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top