Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 90
Default autofilter with macro

I am attempting to perform and autofilter in a macro.
i am using the following syntax and NOTHING happens when the Macro reaches
this point. Im confused. If i record a macro of the actual action it looks
like the syntax i use below. please help.

Sheets("test").Select
Range("B10:AL148").Sort Key1:=Range("E10"), Order1:=xlDescending,
Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal


Note that i want the sort to work regardless of teh number of vertical
entries that are being sorted.. please help.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default autofilter with macro

Can you pick out a column that always has data in it if that row is used?

And is there a reason you didn't include column A in the range to be sorted?
There may be reasons, but it could be a mistake, too.

This code uses column B to determine the last used row and only sorts columns
B:AL.

Dim LastRow as long
with worksheets("test")
lastrow = .cells(.rows.count,"B").end(xlup).row '<-- I used column B
with .range("B10:AL" & lastrow)
.sort key1:=.columns(4), order1:=xldescending, _
header:=xlno, ordercustom:=1, matchcase:=false, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
end with
End with

I specified no header. Change that to xlyes if you have headers in row 10. (I
wouldn't let excel guess if it's my data!).

And .columns(4) is the 4 column in B:AL (column E--same as your range("e10")
stuff).

If you use:
with .range("A10:AL" & lastrow)
Then you'd want .columns(5) to use column E.

And if your original code was used in a commandbutton#_click event (or any code
in a worksheet module), then check to see if the data in that sheet was sorted
instead of the Test worksheet.

(Untested, uncompiled. Watch for typos.)





chuck wrote:

I am attempting to perform and autofilter in a macro.
i am using the following syntax and NOTHING happens when the Macro reaches
this point. Im confused. If i record a macro of the actual action it looks
like the syntax i use below. please help.

Sheets("test").Select
Range("B10:AL148").Sort Key1:=Range("E10"), Order1:=xlDescending,
Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal

Note that i want the sort to work regardless of teh number of vertical
entries that are being sorted.. please help.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default autofilter with macro

ps. Your code showed you were sorting--not filtering.

Dave Peterson wrote:

Can you pick out a column that always has data in it if that row is used?

And is there a reason you didn't include column A in the range to be sorted?
There may be reasons, but it could be a mistake, too.

This code uses column B to determine the last used row and only sorts columns
B:AL.

Dim LastRow as long
with worksheets("test")
lastrow = .cells(.rows.count,"B").end(xlup).row '<-- I used column B
with .range("B10:AL" & lastrow)
.sort key1:=.columns(4), order1:=xldescending, _
header:=xlno, ordercustom:=1, matchcase:=false, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
end with
End with

I specified no header. Change that to xlyes if you have headers in row 10. (I
wouldn't let excel guess if it's my data!).

And .columns(4) is the 4 column in B:AL (column E--same as your range("e10")
stuff).

If you use:
with .range("A10:AL" & lastrow)
Then you'd want .columns(5) to use column E.

And if your original code was used in a commandbutton#_click event (or any code
in a worksheet module), then check to see if the data in that sheet was sorted
instead of the Test worksheet.

(Untested, uncompiled. Watch for typos.)

chuck wrote:

I am attempting to perform and autofilter in a macro.
i am using the following syntax and NOTHING happens when the Macro reaches
this point. Im confused. If i record a macro of the actual action it looks
like the syntax i use below. please help.

Sheets("test").Select
Range("B10:AL148").Sort Key1:=Range("E10"), Order1:=xlDescending,
Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal

Note that i want the sort to work regardless of teh number of vertical
entries that are being sorted.. please help.


--

Dave Peterson


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 90
Default autofilter with macro

Thanks Dave,
That was a ton of information that your provided me.
I will have to absorb what you said and try it out...
I will get back to you.
chuck

"Dave Peterson" wrote:

ps. Your code showed you were sorting--not filtering.

Dave Peterson wrote:

Can you pick out a column that always has data in it if that row is used?

And is there a reason you didn't include column A in the range to be sorted?
There may be reasons, but it could be a mistake, too.

This code uses column B to determine the last used row and only sorts columns
B:AL.

Dim LastRow as long
with worksheets("test")
lastrow = .cells(.rows.count,"B").end(xlup).row '<-- I used column B
with .range("B10:AL" & lastrow)
.sort key1:=.columns(4), order1:=xldescending, _
header:=xlno, ordercustom:=1, matchcase:=false, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
end with
End with

I specified no header. Change that to xlyes if you have headers in row 10. (I
wouldn't let excel guess if it's my data!).

And .columns(4) is the 4 column in B:AL (column E--same as your range("e10")
stuff).

If you use:
with .range("A10:AL" & lastrow)
Then you'd want .columns(5) to use column E.

And if your original code was used in a commandbutton#_click event (or any code
in a worksheet module), then check to see if the data in that sheet was sorted
instead of the Test worksheet.

(Untested, uncompiled. Watch for typos.)

chuck wrote:

I am attempting to perform and autofilter in a macro.
i am using the following syntax and NOTHING happens when the Macro reaches
this point. Im confused. If i record a macro of the actual action it looks
like the syntax i use below. please help.

Sheets("test").Select
Range("B10:AL148").Sort Key1:=Range("E10"), Order1:=xlDescending,
Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal

Note that i want the sort to work regardless of teh number of vertical
entries that are being sorted.. please help.


--

Dave Peterson


--

Dave Peterson

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, AutoFilter... Aline Excel Discussion (Misc queries) 1 July 27th 08 12:27 AM
Autofilter Macro? Danni2004 Excel Discussion (Misc queries) 1 April 29th 08 05:54 PM
Autofilter from macro Brettjg Excel Discussion (Misc queries) 2 June 8th 07 01:45 PM
Macro using autofilter Lorna B Excel Discussion (Misc queries) 5 May 25th 07 06:54 PM
Autofilter Macro Help RonB Excel Discussion (Misc queries) 1 December 30th 04 01:34 AM


All times are GMT +1. The time now is 01:34 AM.

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"