Adding Code to an Existing Command Button with VBA

J

jasoncw

My Excel file has two sheets. The first sheet (we will call this
sheet1) has one command button, and the second sheet (we will call this
sheet2) has two command buttons. If the command button on sheet1 is
clicked, it will copy the entire sheet2 to a new sheet (sheet3). Now,
since the sheet has been copied to a new sheet, the command buttons in
sheet3 lose their code. For example, here is the new code for one of
the command buttons in sheet3:

-Private Sub CommandButton2_Click()

End Sub-

Now what I would like to do is insert some code into this new command
button in sheet3 via the command button code from sheet1 that I
originally used to copy sheet2 to sheet3. The code I would like to
insert is as follows:

-Application.DisplayAlerts = False
Sheets("sheet1").Visible = True
Sheets("sheet1").Select
Sheets("sheet3").delete
Application.DisplayAlerts = True-

My problem is I do not know how to do this in VBA. Can someone help me
out? Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top