View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Lonnie M. Lonnie M. is offline
external usenet poster
 
Posts: 184
Default Finding Last Column in a given Row

Hi, this function will give you the last non-empty cell in the last
column, just change the variable myRow to the row value as you need.

Function LastCell(Optional ws As Worksheet) As Range
Dim myRow&, myCol&, Rng As Range
If ws Is Nothing Then Set ws = ActiveSheet
Set Rng = ws.Cells
Set LastCell = Rng(1)
myRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
myCol = ActiveSheet.Cells(myRow, Columns.Count) _
..End(xlToLeft).Column
On Error Resume Next
Set LastCell = Intersect(Rows(myRow), Columns(myCol))
End Function

HTH--Lonnie M.