Error 1004 - on seemingly valid code

lnagel

Board Regular
Joined
May 28, 2018
Messages
117
I am importing a range of values from a one Workbook into another Workbook - Code looks like this

Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(1)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)
sourceSheet.Activate
targetSheet.Activate
targetSheet.Range("A2:A36").Value = sourceSheet.Range("A2:A36").Value
targetSheet.Range("C2:C36").Value = sourceSheet.Range("C2:C36").Value
targetSheet.Range("D2:D36").Value = sourceSheet.Range("D2:D36").Value
targetSheet.Range("E2:E36").Value = sourceSheet.Range("E2:E36").Value
targetSheet.Range("G2:G36").Value = sourceSheet.Range("G2:G36").Value
targetSheet.Range("H2:H36").Value = sourceSheet.Range("H2:H36").Value
targetSheet.Range("DA4:DA213").Value = sourceSheet.Range("DA4:DA213").Value
targetSheet.Range("DB4:DB213").Value = sourceSheet.Range("DB4:DB213").Value

Works fine until I get to

targetSheet.Range("DA4:DA213").Value = sourceSheet.Range("DA4:DA213").Value - where I get the 1004

Weird thing is - it actually does do the import for this line code before popping the debug

I googled this a bit and saw the suggestion to worksheet(activate) but that didnt change anything

Anyone?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
So there is a twist - I do have have worksheet protection on in the target workbook and all of the cells in the code are exempted from protection

If I turn protection off for the target workbook - everything works fine?????????
 
Upvote 0
If you close & restart xl, do you get the same problem?
 
Upvote 0
And the ANSWER IS : "all of the cells in the code are exempted from protection" was not a correct statement. There are 5 "Special" cells in the DA Column that I have protected. Added more code to "code around" those cells and all working now

Appears that protection means just that - nothing is going to be overwritten for any reason. Protection will let you "read" a protected cell - tho

lots of stuff to learn yet -
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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