Sorting - VBA

K

kirkm

Hi,

I found the following via Google
--
Sub SortColumn(strSheetName As String, strColumnLetter As String)

Dim strColumnRange As String
Dim rngCurrentCell As Range
Dim rngNextCell As Range

strColumnRange = strColumnLetter & "1"

Worksheets(strSheetName).Range(strColumnRange).Sort _
Key1:=Worksheets(strSheetName).Range(strColumnRange)
Set rngCurrentCell =
Worksheets(strSheetName).Range(strColumnRange)

End Sub
--
This sorts a column perfectly.

But the problem is, I need to sort cells which contain first a word
then a number. This only sorts the word.

If I change that to two coluimns, can the above Sort routine
be changed so it sorts both?

Thanks - Kirk
 
G

Greg Glynn

You can add the next column as a secondary search

Sub SortRange1()
Worksheets("Sheet1").Range("A1:C20").Sort _
Key1:=Worksheets("Sheet1").Range("A1"), _
Key2:=Worksheets("Sheet1").Range("B1")
End Sub

You'll need to put your numbers in the second column.
 
K

kirkm

You can add the next column as a secondary search

Sub SortRange1()
Worksheets("Sheet1").Range("A1:C20").Sort _
Key1:=Worksheets("Sheet1").Range("A1"), _
Key2:=Worksheets("Sheet1").Range("B1")
End Sub

You'll need to put your numbers in the second column.


Thanks Greg, it worked FANTASTICALLY!

Cheers - Kirk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top