copy paste macros

jtodd

Board Regular
Joined
Aug 4, 2014
Messages
194
HI i have 2 macros that copy and paste data from multiple sheets to one single sheet.
the issue is that "CopyDPDData" works fine but the "CopyScanData" only copies the one sheet -MON_SCAN and ignores "TUES_SCAN" (Will be expanding to all days of the week if i can get it to work).
As far as i can see the code is exacly the same but with the sheet names changed .

hope it is something obvious but i cannot see it.

VBA Code:
Sub CopyScanData()
    Dim ws As Worksheet
     
    Application.ScreenUpdating = False
    For Each ws In Worksheets
        If ws.Name <> "MON_DPD" And ws.Name <> "TUES_DPD" And ws.Name <> "SUMMARY" And ws.Name <> "WEEKLY" And ws.Name <> "WEEKLY_SCAN" And ws.Name <> "WEEKLY_DPD" Then
            ws.Range("A1:C5000").Copy
            Worksheets("WEEKLY_SCAN").Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
           
        End If
    Next ws
    Rows("1:1").Select
    Selection.Delete Shift:=xlUp
End Sub

Sub CopyDPDData()
    Dim ws As Worksheet
     
    Application.ScreenUpdating = False
    For Each ws In Worksheets
        If ws.Name <> "MON_SCAN" And ws.Name <> "TUES_SCAN" And ws.Name <> "SUMMARY" And ws.Name <> "WEEKLY" And ws.Name <> "WEEKLY_SCAN" And ws.Name <> "WEEKLY_DPD" Then
            ws.Range("A1:Q5000").Copy
            Worksheets("WEEKLY_DPD").Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
           
        End If
    Next ws
    Rows("1:1").Select
    Selection.Delete Shift:=xlUp
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Will you always have values in col A on the scan sheets?
 
Upvote 0
Ok, in that case if you step through the macro line by line using F8, does it go to this line ws.Range("A1:C5000").Copy when you get to the "TUES_SCAN" sheet?
 
Upvote 0
Ok realised not ignoring it but copying it much further down the sheet -
the DPD file copies fine with no spaces - values only but the SCAN file leaves spaces for the rows with formulas in but no data .
the DPD files also have formulas but no data but when coppied does not leave any spaces ?
 
Upvote 0
Ok, how about
VBA Code:
Sub CopyScanData()
    Dim ws As Worksheet
     
    Application.ScreenUpdating = False
    For Each ws In Worksheets
        If ws.Name <> "MON_DPD" And ws.Name <> "TUES_DPD" And ws.Name <> "SUMMARY" And ws.Name <> "WEEKLY" And ws.Name <> "WEEKLY_SCAN" And ws.Name <> "WEEKLY_DPD" Then
            With Worksheets("WEEKLY_SCAN").Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0)
               .Resize(5000, 3).Value = ws.Range("A1:C5000").Value
            End With
        End If
    Next ws
    Rows("1:1").Select
    Selection.Delete Shift:=xlUp
End Sub
 
Upvote 0
Worked like a dream thankyou

any idea why it would not work , the only thing i can see is that the PasteSpecial (xlPasteValues) work on one but not the other .

again thanks
 
Upvote 0
Using pastespecial xlvalues will paste a null string (ie "") whenever you have a formula that returns "" whilst using .Value=.Value will ignore any cells with "" & leave them blank.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,820
Members
449,049
Latest member
cybersurfer5000

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