Add coded active X button using userform

iaindowner

New Member
Joined
Aug 12, 2014
Messages
18
I have a userform which contains a number of textbox fields. It also contains a command button. Upon clicking the command button at the bottom of the user form I want to create a button which contains code dependent on the textbox values in the userform. I already have the code to create the button but I can't work out how to code the button.

Code:
Private Sub Add_Click()
Sheets(Sheet.Value).OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False, Left:=100, Top:=100, Width:=102, Height:=54).Name = NP.NT.Value
Application.ActiveWorkbook.Sheets(Sheet.Value).Shapes(NP.NT.Value).DrawingObject.Object.Caption = NP.NT.Value
 
End Sub

I need to add the code:

Code:
Private Sub [COLOR=#ff0000][U][B]NEWBUTTON[/B][/U][/COLOR]_Click()
Range("I60").End(xlUp).Offset(1, 0).Value = [U][B][COLOR=#ff0000]"RED SQUARE"[/COLOR][/B][/U]
Range("I60").End(xlUp).Offset(0, 1).Value = 1
End Sub

The only issue is that both of the areas highlighted in red above must match the value of one of the textbox fields in the userform which is NP.NT.Value
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Why do you need to create a CommandButton at run time? Why can't you create it at design time and hide it until it's needed?
 
Upvote 0
I am designing a simple EPOS system for someone. The userform allows you to easily add a button which is precoded. It will allow buttons to be added without any vba knowledge or using developer mode.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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