T
Tom Ogilvy
Here is the code I used:
I had random numbers in A1:J100
Column F had unique numbers
The active Cell was in column A (A10)
the last visible row was 28
After the sort, the value in A10 was in A63. A63 was visible and selected.
(in the middle of the visible vertical rows rather at the top of the screen
as in Application.Goto)
Sub Tester1()
mconCaseNumber = "F1"
mconUsedArea = "A1:J100"
' 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:
Bye:
Exit Sub
End Sub
I had random numbers in A1:J100
Column F had unique numbers
The active Cell was in column A (A10)
the last visible row was 28
After the sort, the value in A10 was in A63. A63 was visible and selected.
(in the middle of the visible vertical rows rather at the top of the screen
as in Application.Goto)
Sub Tester1()
mconCaseNumber = "F1"
mconUsedArea = "A1:J100"
' 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:
Bye:
Exit Sub
End Sub