Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
moved vba code from macro to command button, now won't work
You forgot to add Worksheets("Printout"). before one of the ranges. I'd just
keep it in the Macro module, then call it from the Command Button Private Sub PrintPreparation_Click() YourMacro End Sub Alternatively, if you use a command button from the forms toolbar, it will pop up a dialog box asking you which macro you want to link the button to. -- Charles Chickering "A good example is twice the value of good advice." "HGood" wrote: Hi, below is some code. I started out by recording most of the first part as a macro, then adding the remainder to it. When I still had it in the Macro module, it worked fine. I then assigned a Command button to it and copied this code to the module for the Command button. Now when i try to run it, it won't work, it hangs up on Range and Columns and Selection. I finally got it to work for Range and Columns by prefacing it with Worksheets("Printout"). but it won't work for Selection. Can you tell me what I'm missing? Why did it work in the macro module, but not in the command button module? Thanks, Harold 88888888888888888888888888888888888888888 Private Sub PrintPreparation_Click() Sheets("Printout").Visible = True Sheets("Printout").Select Range("b2:f240").Select Selection.Copy 'Columns("B:F").Select Worksheets("Printout").Range("B6:F240").Select Application.CutCopyMode = False Selection.Copy Columns("I:m").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Worksheets("Printout").Range("I6:M233").Select Application.CutCopyMode = False Selection.Sort Key1:=Range("I6:m233"), Order1:=xlAscending, Header:=xlNo, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal Range("I2").Select Columns("A:G").Select Selection.EntireColumn.Hidden = True End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
code for command button not work | Excel Programming | |||
Code created in a Macro not working for a Command Button | Excel Programming | |||
U.S. Command Button Macro won't work in Australian version 2003 | Excel Discussion (Misc queries) | |||
Assign Macro to Command Button doesn't work | Excel Programming | |||
macro code doesnt work in command button | Excel Programming |