column count
You can use this function...
Function MaxColInUse(Optional WS As Worksheet) As Long
Dim X As Long
Dim LastCol As Long
Dim Rw As Variant
If WS Is Nothing Then Set WS = ActiveSheet
With WS
For Each Rw In .UsedRange.Rows
On Error Resume Next
LastCol = .Cells(Rw.Row, Columns.Count).End(xlToLeft).Column
For X = LastCol To 0 Step -1
If .Cells(Rw.Row, X).Value < "" Then
LastCol = X
Exit For
End If
Next
If LastCol MaxColInUse Then MaxColInUse = LastCol
Next
End With
End Function
Rick
"guest" wrote in message
...
is there a way to find last column that has data in a given worksheet??
without selecting the range of data.
|