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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,008
Messages
5,834,850
Members
430,324
Latest member
bosphoruskid

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