ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   programming a button (https://www.excelbanter.com/excel-programming/383891-programming-button.html)

pappaz

programming a button
 
I created a macro that will select specific columns on different sheets and
sort them, and it works fine. I want to create a command button that will do
the same thing, I copied the code from the macro and put into the button and
I get an error when it tries to select the columns. What do I need to change
to make this work? here is the code I have

Columns("A:E").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select

Bob Phillips

programming a button
 
Don't select

With Worksheets("Sheet2")
.Columns("A:E").Sort Key1:=.Range("B2"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"pappaz" wrote in message
...
I created a macro that will select specific columns on different sheets and
sort them, and it works fine. I want to create a command button that will
do
the same thing, I copied the code from the macro and put into the button
and
I get an error when it tries to select the columns. What do I need to
change
to make this work? here is the code I have

Columns("A:E").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select




pappaz

programming a button
 
Bob,
Thank You very much, it does exactly what I wanted now.

-Mike

"Bob Phillips" wrote:

Don't select

With Worksheets("Sheet2")
.Columns("A:E").Sort Key1:=.Range("B2"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"pappaz" wrote in message
...
I created a macro that will select specific columns on different sheets and
sort them, and it works fine. I want to create a command button that will
do
the same thing, I copied the code from the macro and put into the button
and
I get an error when it tries to select the columns. What do I need to
change
to make this work? here is the code I have

Columns("A:E").Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select






All times are GMT +1. The time now is 01:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com