Tuesday, March 30, 2010

How to find the last column


When the usedrange method doesn't work.... try the below method...

Function FindLastColumn()
  Dim LastColumn As Integer
  If WorksheetFunction.CountA(Cells) > 0 Then
    'Search for any entry, by searching backwards by Columns.
    LastColumn = Cells.Find(What:="*", After:=[A1], _
                            SearchOrder:=xlByColumns, _
                            SearchDirection:=xlPrevious).Column
    FindLastColumn = LastColumn
  End If
End Function

No comments:

Post a Comment