Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
code for sorting | Excel Discussion (Misc queries) | |||
Sorting in code | Excel Discussion (Misc queries) | |||
Sorting by code | Excel Discussion (Misc queries) | |||
sorting code | Excel Discussion (Misc queries) | |||
12 digit code sorting | Excel Worksheet Functions |