Command Button vs Form Button

T

T K

Hi:
Please Assume:
a Workbook named Invoice and Worksheets named "Invoice"
and "Parts List"
a Form Button Object and a Command Button on the
("Invoice") Sheet

The following Macro attached to the form button works as
expected .

Sub test1()

' test1 Macro
' Shortcut: Ctrl+z
Sheets("Parts List").Select
Range("U3:U51").Select
Selection.Copy
Range("E3").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlAdd, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("G22").Select
Sheets("Invoice").Select
Range("D7").Select

End Sub

The same code attached to the Command Button does not
work even if I fully quality the Workbook or try to as
follows

Private Sub CommandButton1_Click()

'( Application.Workbooks("Invoice.xls").Worksheets("Parts
List"). Range("U3:U51").Select)

Sheets("Parts List").Select
....
...
Range("D7").Select

End Sub

Any help or direction will be greatly appreciated

T K
 
S

steve

Just copy the the code and paste it into the command button code
(leave out Sub test1() and End Sub)

or use
Run test1
provided test1 is in a standard module.

If test1 is in module1, I like to use
Module1.Test1
to run a macro.
 
T

Tom Ogilvy

Private Sub CommandButton1_Click()
Sheets("Parts List").Range("U3:U51").Copy
Sheets("Parts List").Range("E3") _
.PasteSpecial Paste:=xlValues, _
Operation:=xlAdd, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Sheets("Invoice").Select
Sheets("Invoice").Range("D7").Select
End Sub
 
T

Tom Ogilvy

Just copy the the code and paste it into the command button code
(leave out Sub test1() and End Sub)

since the code has unqualified references that appear to refer to two
separate sheets, the code will need some adjustment. Just calling Test from
the sheet module would avoid that.
 
T

T K

Thanks: Tom, Steve

Both replies work. The code needed the tweaking Tom
applied. Nothing like some good answers to speed things
along
Thanks again!
 

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

Top