Pasting in incorrect sheet

Yorke

New Member
Joined
Nov 29, 2021
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have some code which copies and pastes data from one workbook into another. It pulls data from the correct workbook, and then pastes into the other workbook (this is good). However, instead of pasting into column 'S' in the "data" sheet, it pastes into column 'S' in the "Status" sheet. Please see the code below:

Set OpenBook = Workbooks.Open("C:\Users\yorke\OOH.xlsx")

OpenBook.Sheets("OOH Data").Range("ZVA05Data[[#All],[Item No]]").Copy 'Copy Item No column from table
ThisWorkbook.Worksheets("Data").Range("S1").PasteSpecial xlPasteValues 'Paste values into Data tab in S1

As you can see, I don't even mention the "status" sheet, however there are some lines of code referring to the "status" sheet earlier in the code. Is there anyway I can make this more specific? It began not working with this and now another column is also pasting in the incorrect sheet.

Thanks in advance.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Sometimes a problem is not where you think it is. This code looks OK but please show us all the code for the entire Sub. For example, there could be something happening after this code that causes the problem. Have you stepped through the code with F8 to see what happens on that exact line of code with the Paste?

Also, I suggest applying code tags when you paste code into post. Select the code then click the VBA icon in the editor. This will preserve the spacing of your code and color-code keywords.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

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