Code:
Sub SortACol(strSheetName As String, strEnd As String, Column as string)
Dim strColumnRange As String
Dim rngCurrentCell As Range
Dim rngNextCell As Range
strColumnRange = "A1:O" & Trim(strEnd)
Worksheets(strSheetName).Range(strColumnRange).Sort _
Key1:=Worksheets(strSheetName).Range(column &"1"), Order1:=xlAscending
Set rngCurrentCell = Worksheets(strSheetName).Range(strColumnRange)
End Sub
Can I have details on what to change to make that Sort only the Column passed in ?
Do I need all the DIMs and strColumnRange, plus know the last row (strEnd) in advance ?
ASSUMING YOU MEAN: You only one to sort ONE column
(instead of wanting to sort a range
based on one column)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Sorting is achieved by this line:
Code:
Worksheets(strSheetName).Range(strColumnRange).Sort Key1:=Worksheets(strSheetName).Range(column &"1"), Order1:=xlAscending
I don't know what you pass into the routine for the
Column variable: Sub SortACol(strSheetName As String, strEnd As String,
Column as string)
Is it a string that is
a single column reference? e.g. "A" or "F" or "AX", etc
Is it a string that is a
single column as a range? e.g. "A:A" or "B:B" etc
If it's a
single column as a range (e.g. "A:A") then all that's needed is:
Calling routine
Code:
Sub test()
SortACol "Sheet1", "E:E"
End Sub
Sort routine
Code:
Sub SortACol(strSheetName As String, SortColumn As String)
Sheets(strSheetName).Range(SortColumn).Sort Key1:=Range(SortColumn), Order1:=xlAscending, Header:=xlNo
End Sub
N.B. If your column has a header, you'll need to change
Header:=xlNo to
Header:=xlYes