Skip to content

Instantly share code, notes, and snippets.

@hoffstein
Created July 27, 2011 13:41
Show Gist options
  • Save hoffstein/1109377 to your computer and use it in GitHub Desktop.
Save hoffstein/1109377 to your computer and use it in GitHub Desktop.
Excel find last column
Function FindLastColumn(Optional sheetToSearch As Worksheet) As Long
If sheetToSearch Is Nothing Then Set sheetToSearch = ActiveSheet
On Error GoTo handler
FindLastColumn = sheetToSearch.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Exit Function
handler:
FindLastColumn = 1 ' No data on sheet
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment