Command button problem

Anders

New Member
Joined
Jan 13, 2004
Messages
2
Hi,
I've written a short macro that works just fine when I run it from the VB editor. However when I try to tie the code to a command button it doesn't work anymore. This is the code I've written:

Sub CreatePosWorksheet()
Dim x As String
x = Mid(Range("A5").Value, 11, 10)
Sheets("Dummy Pos").Copy Before:=Sheets("ränta")
Sheets("Dummy Pos (2)").Name = "Positions " & x
End Sub

When I try to run the macro by pressing the command button the following error message pops up: Copy method of Worksheet class failed.

Does anyone know what the problem might be?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try setting the commandbutton's
'Takefocusonclick' property to false
 
Upvote 0

Forum statistics

Threads
1,203,690
Messages
6,056,755
Members
444,889
Latest member
ibbara

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