Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro code doesn't work with Button

Hello everyone: Need some help. I am not an Excel Person, but got
stuck with a project because I was off the day they took the vote on
who should do it.

So far I've been pretty lucky just recording marco's and then placing
the marco code on the click event of a button. Except for the code
below. It runs fine as a macro but bombs when the code is copied to a
button. It's just doing a filter then copying a range of cells from
one worksheet to a new worksheet.

The first line of code that bombs is "Columns("A:E").Select.

Any help would be appreciated.

================================================== ================

Dim x As String
Dim y As String

x = ActiveWorkbook.Name
Selection.AutoFilter Field:=6, Criteria1:="<"
Columns("B:F").Select
Selection.Copy
Workbooks.Add
y = ActiveWorkbook.Name
ActiveSheet.Paste
Columns("A:E").Select
Columns("A:E").EntireColumn.AutoFit
Range("A6").Select

Windows(x).Activate
Range("A10").Select
Application.CutCopyMode = False
Selection.AutoFilter Field:=6
Windows(y).Activate
Range("A5").Select
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Macro code doesn't work with Button

"but bombs when the code is copied to a button."

Are you copying the code to a sheet module?
If so, you must qualify all range references with the sheet the range is on...
Workbooks(y).Columns("A:E").Select

Tips on posting to Excel newsgroups here...
http://www.cpearson.com/excel/newposte.htm
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"eighthman11"
wrote in message
Hello everyone: Need some help. I am not an Excel Person, but got
stuck with a project because I was off the day they took the vote on
who should do it.
So far I've been pretty lucky just recording marco's and then placing
the marco code on the click event of a button. Except for the code
below. It runs fine as a macro but bombs when the code is copied to a
button. It's just doing a filter then copying a range of cells from
one worksheet to a new worksheet.
The first line of code that bombs is "Columns("A:E").Select.
Any help would be appreciated.

================================================== ================

Dim x As String
Dim y As String

x = ActiveWorkbook.Name
Selection.AutoFilter Field:=6, Criteria1:="<"
Columns("B:F").Select
Selection.Copy
Workbooks.Add
y = ActiveWorkbook.Name
ActiveSheet.Paste
Columns("A:E").Select
Columns("A:E").EntireColumn.AutoFit
Range("A6").Select

Windows(x).Activate
Range("A10").Select
Application.CutCopyMode = False
Selection.AutoFilter Field:=6
Windows(y).Activate
Range("A5").Select
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
Macro Does not Work on Button [email protected] Excel Worksheet Functions 4 March 28th 09 03:46 PM
Macro Button in a work sheet Finance Guru Excel Discussion (Misc queries) 9 November 15th 07 09:17 PM
moved vba code from macro to command button, now won't work Charles Chickering Excel Programming 0 January 12th 07 10:18 PM
code for command button not work simon Excel Programming 12 December 5th 06 04:34 AM
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 09:35 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"