By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


FindLastCol(1) - find the last column passed a row udf



Function FindLastCol(r As Long) As Long
'Version: 1.000
'Purpose: This routine will find the last row in the spread sheet for the passed column
'Hidden column aren't included
' c is the column to use to find the last row
Dim prevcol As Long

'Go to the end
If r <= 0 Then
    FindLastCol = 0
    Exit Function
    
End If

Cells(r, ActiveSheet.Cells.Columns.Count).Select

  Selection.End(xlToLeft).Select
prevcol = 0
Do While Trim(ActiveCell.Text) = "" And ActiveCell.Column <> 1
      Selection.End(xlToLeft).Select
      
      If ActiveCell.Column = prevcol Then
        FindLastCol = ActiveCell.Column
        Exit Function
      Else
        prevcol = ActiveCell.Column
        
      End If
    
Loop
If ActiveCell.Text = "" Then
    FindLastCol = 0
Else
    FindLastCol = ActiveCell.Column
End If

End Function