VBA paste help

bolo

Active Member
Joined
Mar 23, 2002
Messages
423
Hi i was wondering if ne VBA experts can help.
I have a work sheet macro than run s off a command button to copy information from one sheet to another. the problem is the macro only works half the time. the activesheet.paste seems to generate a run time 1004 error. THe takeonfocus property of the buttons are false.
The worksheets are protected and hidden but before i paste the sheets are unhidden and unprotected. What is annoying is that it does work sometimes but not others. i don't undersatnd

Thanks for the help
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

bolo

Active Member
Joined
Mar 23, 2002
Messages
423
Yep heres the code
I am well aware of using the 'with' key word but the problems occured after i inserted this key word
If response = vbYes Then
Sheets(nam).Visible = xlSheetVisible

Sheets(nam).Range("A1:F12").Copy
Assumptions.Visible = xlSheetVisible
Assumptions.Unprotect
'Assumptions.Select
'Assumptions.Range("B3:G14").Select
ActiveSheet.Paste Destination:=Assumptions.Range("B3:G14")
Assumptions.Visible = xlSheetHidden
Assumptions.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
end if

x2

Update. This macro works every 4 trys. the first paste causes the error the first time. The second paste causes the error the second time i run it.
the third time the first paste line causes the problem and then it works. i don't get it.

thx for the quick reponse!
This message was edited by bolo on 2002-10-16 20:42
 

bolo

Active Member
Joined
Mar 23, 2002
Messages
423
Hi problem solved. i just moved the protect and visible codes around.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,949
Messages
5,599,020
Members
414,274
Latest member
LisaGreen

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
Top