L
Laurence Lombard
The code below sorts a range to the current column and finds the last
occurrence of the value in Activecell. This works well except if the current
column has formulas and values mixed - then Find returns "Nothing"
(displayed by my message). It seems to be inconsistent though (does not
always return Nothing). Can anyone explain what is going on?
Thanks
Laurence
Sub SortToCurrentColumn_Click()
'Sort_to_CurrentColumn()
Sheets("Cash Bks").Activate
CurrentColumn = ActiveCell.Column
CurrentCellValue = ActiveCell.Value
Lastrow = Range("B10000").End(xlUp).Row
Range("A2", "O" & Lastrow).Sort _
Key1:=Cells(3, CurrentColumn), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Set Foundcell = Range(Cells(1, CurrentColumn), Cells(Lastrow,
CurrentColumn)).Find(What:=CurrentCellValue, _
LookIn:=xlValues, LookAt:=xlWhole, searchdirection:=xlPrevious)
If Foundcell Is Nothing Then
MsgBox "Nothing"
Else
Foundcell.Activate
End If
End Sub
occurrence of the value in Activecell. This works well except if the current
column has formulas and values mixed - then Find returns "Nothing"
(displayed by my message). It seems to be inconsistent though (does not
always return Nothing). Can anyone explain what is going on?
Thanks
Laurence
Sub SortToCurrentColumn_Click()
'Sort_to_CurrentColumn()
Sheets("Cash Bks").Activate
CurrentColumn = ActiveCell.Column
CurrentCellValue = ActiveCell.Value
Lastrow = Range("B10000").End(xlUp).Row
Range("A2", "O" & Lastrow).Sort _
Key1:=Cells(3, CurrentColumn), Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
Set Foundcell = Range(Cells(1, CurrentColumn), Cells(Lastrow,
CurrentColumn)).Find(What:=CurrentCellValue, _
LookIn:=xlValues, LookAt:=xlWhole, searchdirection:=xlPrevious)
If Foundcell Is Nothing Then
MsgBox "Nothing"
Else
Foundcell.Activate
End If
End Sub