Hi Tom,
Thanks for your replies.
I'm almost home and dry.
I've used the Intersect method on a column that contains unique
values. I can unambiguously find the new row after the sort. I can
create a range object for the new location of the cell that was active
before the sort.
One problem remains. Do you (or anyone else) have any ideas please?
The show method of the new location cell's range object doesn't scroll
me to the cell, ie this code line doesn't work as I expect :
rngNewCell.Show
Thanks for your help.
Geoff
I don't suppose you'll need it, but this is how I ended up doing it:
' Ensure CaseNumber range name exists:
RetVal = RangeExists(mconCaseNumber)
If Not RetVal Then
RangeNameMissing_CannotSort mconCaseNumber
GoTo Bye
End If
' Ensure UsedArea range exists:
RetVal = RangeExists(mconUsedArea)
If Not RetVal Then
RangeNameMissing_CannotSort mconUsedArea
GoTo Bye
End If
' Turn off screen:
AllowScreenUpdates False
' Get active cell's range, column and row numbers:
Set rngOldCell = ActiveCell
lngOldRow = rngOldCell.Row
lngOldCol = rngOldCell.Column
' Get Case Number column as range:
Set rngCaseNoCol = Intersect(Range(mconCaseNumber).EntireColumn,
Range(mconUsedArea))
' Test for intersection:
If rngCaseNoCol Is Nothing Then GoTo InvalidCaseNumberIntersection
' Get Case Number column number:
lngCaseNoCol = rngCaseNoCol.Column
' Get Case Number for active row:
strCaseNo = Cells(lngOldRow, lngCaseNoCol).Value
' Execute sort on Case Number column:
Range(mconUsedArea).Sort Key1:=Range(mconCaseNumber),
Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
' Find old case number in Case Number column now it's sorted:
Set rngNewRow = rngCaseNoCol.Find(strCaseNo)
' Shouldn't happen, but test that case number is found:
If rngNewRow Is Nothing Then GoTo CaseNumberNotFound
' Get new row number of cell that was active at start:
lngNewRow = rngNewRow.Row
' Get new range of cell that was active at start:
Set rngNewCell = Cells(lngNewRow, lngOldCol)
' Move to new cell location:
rngNewCell.Activate
rngNewCell.Show ' PROBLEM WITH THIS LINE !
' Put sort order into footer:
ChangeFooter "Sorted by Case Number"
GoSub CleanUp
' Message user:
strMessage = "Now ordered by CASE NUMBER."
intOptions = vbInformation + vbOKOnly
strHeading = "Sort Complete"
MsgBox strMessage, intOptions, strHeading
Bye:
Exit Sub