Copy and paste with unlock and lock worksheet

Project217

New Member
Joined
Mar 7, 2022
Messages
24
Office Version
  1. 365
Platform
  1. MacOS
Hi all.

Im Just having some trouble with the below VBA, works the first time perfectly but every second time it crashes and comes up with run time error 1004 PasteSpecial method of range class failed.
Also, I'm looking to add to this macro an email alert with just text only,
Any help would be awesome.

Sub PastTableToMasterSheet()
ActiveSheet.Unprotect Password:=""
Range("Table34").Copy
Sheets("Master Sheet").Unprotect Password:=""
Sheets("Master Sheet").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulas
Sheets("Master Sheet").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:=""
Application.CutCopyMode = False
Rows("26:26").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.DELETE Shift:=xlUp
Range("B12").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:=""
MsgBox "Order Sent"
End Sub
 
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:=""
Add this line
VBA Code:
   Range("Table34").ClearContents

Before this line
VBA Code:
  ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:=""
Thank you, Yes it works, However it just clears the table and starts a new row below the cleared or blank rows, is there a way to start back on row 26 and also not clear the contents or row 25, (This is the first row in the table and I need the contents for a conditional format on the master sheet.)
 
Upvote 0

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
Add this line
VBA Code:
   Range("Table34").ClearContents

Before this line
VBA Code:
  ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:=""
Hi. Thanks very much, it worked, However it clears the table leaving blank rows in the table then new data is added to a new row, so the copy to master sheet copy's the blank rows. Also I need to have in NEW DATA BELOW in row 25 on the table for conditional formatting on the master sheet. any idea how this could be achieved?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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