Thread: column count
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default column count

Here is a function that returns the last column...

sub test
msgbox lastcolumn 'activesheet
msgbox lastcolumn(sheets("Sheet1"))
end sub

Public Function LastColumn(Optional ByVal wks As Worksheet) As Long
Dim lngLastColumn As Long

If wks Is Nothing Then Set wks = ActiveSheet
On Error Resume Next
LastColumn = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
If LastColumn = 0 Then lngLastColumn = 1
End Function
--
HTH...

Jim Thomlinson


"guest" wrote:

is there a way to find last column that has data in a given worksheet??
without selecting the range of data.