Add a button and macro from one worksheet to another

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
I have a very useful button I use on a worksheet to paste data. I want to copy this button (and it's macro) to another sheet. Is this possible? If so. how do I go about it?

Thank You, :eek:
Michael
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,884
Office Version
  1. 365
Platform
  1. Windows
Go into design mode (green triangle icon on the toolbar)
Right-click the button, "copy".

Go to the other sheet, right click and "Paste"

That'll do the button bit......... Is the button from a "Forms" button or a "Command" button?
 

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
It is just a button floating on a spreadsheet. I got it from...... the forms toolbar.

Thank You,
michael
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,884
Office Version
  1. 365
Platform
  1. Windows
Ok Michael

Assuming the other bit worked, you've now got a copy on your other sheet.

If the button's a "Forms" one, the macro should copy accross automatically. If not........

On the original button, right click, select "Assign Macro" and see the name of the macro already assigned (should be in the top dropdown box.)
Now do the same with the new Button, selecting the same Macro from the dropdown.
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,611
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

Maybe the easiest way is something like this :

Code:
Sub Button1_Click()
    MsgBox "Test"
End Sub


Sub Button2_Click()
    Button1_Click
End Sub

Where Button1 is the initial button and Button2 is the copied one.


Regards.
 

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
Isn't the green triangle design mode for Microsoft Access? Can't find it!!


Michael :oops:
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,884
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Up the top - View / Toolbars / Visual Basic
 

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
The button is actually in a sheet. I need to copy it to another sheet. It goes with the spreadsheet, it does not stay in a toolbar. Hope this clears up what I want to do.

I can create a button on a sheet. That is easy. I need to know how to either copy the code behind it, with it or copy and paste the code. If I copy and paste the code, where to put it???


Michael
 

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,884
Office Version
  1. 365
Platform
  1. Windows
I'm perfectly aware that your button is not attached to a toolbar.

My previous post was to answer your question of where to find the "Green Triangle" i.e. design mode button.
My suggested actions will bring up the Visual basic toolbar, which normally contains the design mode button.

Going in to design mode will then allow you to right click your buttons and access the code behind the button in order to copy it.

But, as I've already stated, if your button is, indeed a Forms button, then the code should automatically follow it accross when you copy and paste the button, and you shouldn't even need to go into design mode for that.
 

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
I am so sorry for being ignorant.
I could not find a triangle. I right click on a toolbar and hit customize. I then found a triangle under control toolbox. I then added it to my standard toolbar. I then copied and pasted as you suggested and it works great.
Thank You,
Michael :pray:
 
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,163,990
Messages
5,834,761
Members
430,317
Latest member
karenmi

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