PasteSpecial (Column Widths & Values) from multiple sheets into one master sheet VBA

mhockey88

New Member
Joined
Jul 9, 2015
Messages
5
Hi there - I am trying to use VBA to take each of 15 tabs in my workbook, paste the data into a master sheet (as values and maintaining column widths) and then delete the original tabs after that

I'm having trouble as I can't figure out how to use pastespecial in combination with End(xlUp), as I would like the data from each successive tab to paste in the next empty row

Thanks in advance for all the help!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You do realize that the columns will resize to whatever size the last sheets copied columns are?

Uncomment
Code:
ws.Delete
once you know the rest of the code is working.

Change Sheets("Master") to your mastersheets name.

Rich (BB code):
Sub yyy()
    Dim ws As Worksheet, lc As Long, lr As Long
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> "Master" Then
            lc = ws.Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
            lr = ws.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious, False).Row
            ws.Range(ws.Cells(1, 1), ws.Cells(lr, lc)).Copy
            
            With Sheets("Master").Range("A1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
                .PasteSpecial xlPasteColumnWidths
                .PasteSpecial xlPasteValues, , False, False
            End With
            
            Application.CutCopyMode = False

            Application.DisplayAlerts = False
            'ws.Delete
            Application.DisplayAlerts = True

        End If
    Next
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Thanks Mark. As far as the column resizing I would've thought so, but I think something odd must have been going on a few of the files which for some reason was fixed by pasting as values and column widths. Regardless, I've used your code and it's working perfectly, thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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