Share via

VBA pulling data from wrong worksheet

Anonymous
2016-09-15T03:36:34+00:00

Below is a snppet of VBA code I am using to move data from one excel file to another.  It works fine until it gets to the code in bold and underlined.  Instead of pulling the data from the "Block_Check" workbook as the lines above it do, it instead pulls it from the "Cancelled OB" workbook referenced in the next set of code.  How do I fix this?

Set wb = Workbooks("DC Reporting.xlsx")

    Set wb6000 = Workbooks("DC Reporting.xlsm")

        rws = wb6000.Sheets("Profit Hold").Cells(Rows.Count, 1).End(xlUp).Row + 1

        With wb.Sheets("Block_Check")

            na = .Cells(Rows.Count, 1).End(xlUp).Row - 1

            'A36->A2

            .Cells(36, 1).Resize(na, 3).Copy Destination:=wb6000.Sheets("Profit Hold").Cells(2, 1)

            'D36->E2

            .Cells(36, 4).Resize(na, 4).Copy Destination:=wb6000.Sheets("Profit Hold").Cells(2, 5)

            'H36->J2

           .Cells(36, 8).Resize(na, 1).Copy Destination:=wb6000.Sheets("Profit Hold").Cells(2, 10)

       End With

    Set wb = Workbooks("DC Reporting.xlsx")

    Set wb6000 = Workbooks("DC Reporting.xlsm")

        rws = wb6000.Sheets("Cancelled OBs").Cells(Rows.Count, 1).End(xlUp).Row + 1

        With wb.Sheets("Cancelled OB")

            na = .Cells(Rows.Count, 1).End(xlUp).Row - 1

            'A36->A2

            .Cells(36, 1).Resize(na, 3).Copy Destination:=wb6000.Sheets("Profit Hold").Cells(2, 1)

            'B36->C2

            .Cells(36, 2).Resize(na, 9).Copy Destination:=wb6000.Sheets("Profit Hold").Cells(2, 3)

       End With

Thanks,

Shelli

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2016-09-15T03:59:26+00:00

Re:  sequentially copy and paste

It appears that the "Cancelled OB" data is being pasted over the top of the "Block_Check" data.

Cells(2, 5) gets four columns of data pasted.

-then-

Cells(2, 3) gets nine columns of data pasted.

'---

Jim Cone

Portland, Oregon USA

https://www.dropbox.com/sh/ttybwg5e9r31twa/AAAnyBTHPX5XsTDp10ItTcw4a?dl=0

(free & commercial excel programs

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2016-09-15T04:44:47+00:00

    That was only 1 of the issues.  I forgot to change the name in the second set.  That's what I get for working so late and copying and pasting.  I probably wouldn't have seen it if you hadn't pointed out the overlap. 

    Thanks,

    Shelli

    Was this answer helpful?

    0 comments No comments