Function to select second-to-last non-empty cell

S

sandr5

I'm in need of a function that will select the second-to-last used sel
in a specified row or column.

I have a function that selects the LAST cell...(I've included the cod
below)but now I need another function that selects the SECOND-TO-LAS
cell can some code be inserted into this to make that happen?....thank
in advance.




Function Last_Cell_value(Col_or_Row_Range As Range)
'
' Last_Cell_value Macro
' Returns the value in the last occupied cell of a _
single column or row range. *Range cannot include _
row 65536 or column IV.*
'
'
' =Last_Cell_value($A$5:$Z$5) for ROW
' =Last_Cell_value($A$1:$A$500) for COLUMN
'
'
'
If Col_or_Row_Range.Columns.Count = 1 Then
If Col_or_Row_Range.Cells _
(Col_or_Row_Range.Rows.Count, 1) <> "" Then
Last_Cell_value = _
Col_or_Row_Range.Cells(Col_or_Row_Range.Rows.Count, 1)
Else
Last_Cell_value = _
Col_or_Row_Range.Cells _
(Col_or_Row_Range.Rows.Count + 1, 1).End(xlUp)
End If

Else

If Col_or_Row_Range.Cells _
(1, Col_or_Row_Range.Columns.Count) <> "" Then
Last_Cell_value = _
Col_or_Row_Range.Cells(1, Col_or_Row_Range.Columns.Count)
Else
Last_Cell_value = _
Col_or_Row_Range.Cells _
(1, Col_or_Row_Range.Columns.Count).End(xlToLeft)
End If

End If
End Functio
 
Top