View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default sorting by Contract #'s

I don't think you're ever going to be able to sort numbers into the order you
want using plain old excel's dialogs. Maybe a helper column. Maybe changing
the data.

Maybe something like:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim RngToSort As Range
Dim LastRow As Long
Dim StartCell As Range

Set wks = ActiveSheet
With wks
Set StartCell = .Range("H11")
LastRow = .Cells(.Rows.Count, StartCell.Column).End(xlUp).Row

Set RngToSort = .Range("A11:H" & LastRow)

With RngToSort
.Cells.Sort Key1:=.Columns(8), Order1:=xlAscending, _
key2:=.Columns(2), order2:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End With

End Sub

I figure you know if the data has headers. Change xlyes to xlno if there are no
headers--but why take a chance that excel will guess incorrectly.

I used column H to find the last used row--is that ok?

And I don't how many columns are in the range to be sorted. I use A:H.

And do you still want to sort by the second column in the range (as the
secondary key)?






Eric wrote:

Dave,

What if I use a list box and ask for a certain contract #. Also, What about
the first part of my problem?

Eric

"Dave Peterson" wrote:

I don't think you're going to get excel to sort numbers using your custom sort
criteria. Sorting numbers is gonna be ascending or descending.

Maybe you could add another field that returns a number for each of the
contracts so you could sort by that field.


Eric wrote:

Hello,
I am needing help from the excel Masters. I am completely lost and have
tried to find my way for the past 3 days. I have given up. Please help me.

If I sort from Column A to column H this macro works great

Dim sheet1 As Worksheet
Dim myrange As Range
Dim lrow As Long
Set sheet1 = ActiveSheet
Set myrange = sheet1.Range("A11")
lrow = sheet1.Cells(sheet1.Rows.count, myrange.Column).End(xlUp).Row

Set myrange = myrange.Resize(lrow - myrange.Row + 1, 6)

myrange.sort key1:=Range("A12"), Order1:=xlAscending, _
Key2:=Range("B12"), Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlSortNormal

Now I need to reverse this whole thing and place the contract #'s in column
H instead of A and the above macro doesn't work. What do I need to do.

Next, I need to sort all of this info by date or by contract #. So, I need
a macro to ask me what contract number to be first so that my program will
graph it.
ie:
123
354
456

Now I want Contract 456 on top.
456
123
354

But now I want Contract 354 on top.

354
123
456

I am sorry to make this so difficult. Hope some on can help me. My email
is

Eric Dickson


--

Dave Peterson


--

Dave Peterson