Hi,
Trying to write a macro to find the range on a sheet where userdata are presented.
My starting point here is to find the first and last used column, and row, and by that information create my customized range.
However, I cant find the correct command to set the first used column. I'm using the following code which works in Excel 2003, but in Excel 2007 it only returns a "0".
Function xlFirstCol()
With ActiveSheet
On Error Resume Next
xlFirstCol = .Cells.find("*", .Cells(.Cells.Count), xlFormulas, xlWhole, xlByColumns, xlNext).Column
If Err <> 0 Then xlFirstCol = 0
End With
ActiveCell.Value = xlFirstCol
End Function
My code to find the last column works perfect in both 2003 and 2007 though.
Function xlLastCol()
With ActiveSheet
On Error Resume Next
xlLastCol = .Cells.find("*", .Cells(1), xlFormulas, xlWhole, xlByColumns, xlPrevious).Column
If Err <> 0 Then xlLastCol = 0
End With
ActiveCell.Value = xlLastCol
End Function
How should I do to find the first column in my sheets which contains any data?
Bookmarks