Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Events for programatically created commandbutton?

Status
Not open for further replies.

tgomm

Technical User
Oct 1, 2002
1
US
I've got an excel macro that adds a row to a worksheet. Each new row is created with it's own Delete button (I'd like have the button delete its row when clicked).

My understanding is that I need to have a separate event procedure for each Delete button. But the buttons are created by a macro and I don't know how to have the macro write a new event procedure for each new button.

Ideally I'd like to have each Delete button call the same procedure but just pass some reference parameter (like the row number).

Does anyone have any ideas on how to do this?

Thanks!!!

- Troy -
 
Hey !
I've got exactly the same problem You have ! Did You solve it anyway ? Did anybody answered You ? If so, can You PLEASE let me know? THANKS in advance !!!

Ciao !

Marco
 
Try something like this when you create then buttons. It adds event code for the button the the worksheet.
What you have to replace with variables is surrounded with <>.


ThisWorkbook.VBProject.VBComponents.Item(&quot;<sheetName>&quot;).CodeModule.InsertLines 1, vbcrlf & _
&quot;Private Sub <buttonName>_Click()&quot; & vbcrlf & _
&quot; deleteRow <rowNr>&quot; & vbcrlf & _
&quot;End Sub&quot; & vbcrlf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top