![]() |
Function to select second-to-last non-empty cell
I'm in need of a function that will select the second-to-last used sell in a specified row or column. I have a function that selects the LAST cell...(I've included the code below)but now I need another function that selects the SECOND-TO-LAST cell can some code be inserted into this to make that happen?....thanks 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 Function -- sandr5 ------------------------------------------------------------------------ sandr5's Profile: http://www.excelforum.com/member.php...o&userid=32675 View this thread: http://www.excelforum.com/showthread...hreadid=524803 |
All times are GMT +1. The time now is 12:46 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com