Hi folks, quick query on UsedRange.
I need to find out the last column that has data in - I want to use the "UsedRange" property of the workbook but am having problems.
This is what I'm using so far:
'Next, go through the columns in the worksheet...
wTscWorkbook.Activate
rngUsed = ActiveWorkbook.Sheets("Sheet1").UsedRange
For i = 2 To rngUsed.Columns
If Left(wTscWorkbook.Sheets("Sheet1").Cells(1, i), 1) <> "W" Then
'The column is not a weekly figure. Delete it.
wTscWorkbook.Sheets("Sheet1").Columns(i).Delete
i = i - 1
End If
Next i
I want to check each column in wTscWorkbook, and the column header doesn't start with "W" then I need to delete the column - as the information in all the "W" columns will eventually be pasted into another workbook.
Trouble is, the code errors on the line rngUsed = ActiveWorkbook.Sheets("Sheet1").UsedRange, error 91: Object Variable not set...
...What am I doing wrong??
Ad