Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default code for sorting

I can't get this to do what I want for the life of me...

Basically, I want a block of VB code that will sort the
currently selected set of cells in ascending order by
column B then by column C with no header row.

I want to select the group of cells, then click a button
on the tool bar that performs the sort as described. I
know a little VB but obviously not enough to figure this
out...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default code for sorting

I tried doing the macro, but it hardcoded in the cells
that I had selected. I wasn't sure how to sort whatever's
current...

-----Original Message-----
When in doubt, records a macro and look at the recorded

code. In this case,
this pretty much pops out. (Yes, I did make some key

changes to make it more
general.)

Option Explicit

Sub Macro1()
Selection.Sort _
Key1:=Selection.Cells(1), Order1:=xlAscending, _
Key2:=Selection.Cells(2), Order2:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
End Sub

--
Bob Kilmer

"wessj" wrote in message
...
I can't get this to do what I want for the life of me...

Basically, I want a block of VB code that will sort the
currently selected set of cells in ascending order by
column B then by column C with no header row.

I want to select the group of cells, then click a button
on the tool bar that performs the sort as described. I
know a little VB but obviously not enough to figure this
out...



.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default code for sorting

"Selection.Sort (etc.)" causes Sort to operate on the currently selected
range.
"Selection.Cells(1)" stands for the first (top-left) cell in the currently
selected range.
"Selection.Cells(2)" stands for the cell "next to" the first (top-left) cell
in the currently selected range. This will be the next cell to the right, if
the selection is more than one cell wide, or it will be the next cell down
if the selection is one cell wide (but more than two cells high). If the
selection is only one cell, using "Selection.Cells(2)" will raise an error.

--
Bob Kilmer


"wessj" wrote in message
...
I tried doing the macro, but it hardcoded in the cells
that I had selected. I wasn't sure how to sort whatever's
current...

-----Original Message-----
When in doubt, records a macro and look at the recorded

code. In this case,
this pretty much pops out. (Yes, I did make some key

changes to make it more
general.)

Option Explicit

Sub Macro1()
Selection.Sort _
Key1:=Selection.Cells(1), Order1:=xlAscending, _
Key2:=Selection.Cells(2), Order2:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
End Sub

--
Bob Kilmer

"wessj" wrote in message
...
I can't get this to do what I want for the life of me...

Basically, I want a block of VB code that will sort the
currently selected set of cells in ascending order by
column B then by column C with no header row.

I want to select the group of cells, then click a button
on the tool bar that performs the sort as described. I
know a little VB but obviously not enough to figure this
out...



.



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 sorting Jack Sons Excel Discussion (Misc queries) 4 September 29th 09 08:23 AM
Sorting in code Ayo Excel Discussion (Misc queries) 4 July 19th 08 11:47 PM
Sorting by code Jay Excel Discussion (Misc queries) 1 February 8th 08 05:55 PM
sorting code Larry Excel Discussion (Misc queries) 5 August 2nd 06 07:40 AM
12 digit code sorting Mark Excel Worksheet Functions 5 October 31st 05 10:21 PM


All times are GMT +1. The time now is 10:00 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"