Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
code for command button not work simon Excel Programming 12 December 5th 06 04:34 AM
Code created in a Macro not working for a Command Button Amber_D_Laws[_8_] Excel Programming 15 January 13th 06 10:35 PM
U.S. Command Button Macro won't work in Australian version 2003 Ron in Dallas Excel Discussion (Misc queries) 1 December 23rd 05 05:08 PM
Assign Macro to Command Button doesn't work CLS Excel Programming 2 May 31st 05 05:42 PM
macro code doesnt work in command button The Grinch[_9_] Excel Programming 4 July 22nd 04 06:28 PM


All times are GMT +1. The time now is 08:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"