• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA to create and program a command button

wcso105

New Member
I have an excel spreadsheet that works just as I'd like it to. I am trying to create the same sheet using VBA so I can have multiple sheets in the same workbook. Copy/paste does not work as it does not copy/paste the 3 command buttons. My command button code is basic and I can create the button but not add the code via VBA.

One code is:
>>> use code - tags <<<
Code:
Private Sub CommandButton2_Click()
Worksheets("Sheet1").PageSetup.PrintArea = Range("L2").Value & ":" & Range("L3").Value
PrintPreview
End Sub
Any help adding this to a spreadsheet via VBA is appreciated. My current spreadsheet is attached and what I have tried is at the bottom of the code. When I create a new sheet and run the macro, it prints everything instead of what is requested. Using the sheet created without VBA, it works perfectly.
 

Attachments

  • Ed Sawyer Builders.xlsm
    725.6 KB · Views: 4
Last edited by a moderator:
Try this sample.
I modified Your code too.
Note: I cannot verify Your PrintPreview
I tested it with PrintOut
 

Attachments

  • Ed Sawyer Builders.xlsb
    713.4 KB · Views: 1
Back
Top