Don\'t know what I\'m missing, but the examples I see posted do not appear to work.
I import data from a web query. I set the query to clear unused cells when it re
I only needed to use Worksheets("Sheet1").UsedRange.Calculate after deleting rows to reset the range.
This may or may not suit your data needs, but if your data is all in one contiguous block, you can use CurrentRegion instead of UsedRange, like this:
With Cells(1, 1).CurrentRegion
MsgBox "I have " & .Rows.Count & " rows and " & .Columns.Count & " columns of data."
End With
Of course, if the region you care about does not start at cell A1, or if your sheet contains multiple contiguous regions that you care about, this option will not work. Depending on how predictable your data is, you can usually find at least one cell in each block of data, and once you have that, CurrentRegion will give you the range of the entire block.
Works for me on all versions of excel
This worked for me:
Worksheets("Sheet1").UsedRange.Clear
Worksheets("Sheet1").UsedRange = ""
It appears that inserting a value into the UsedRange resets it. After this action I can go
MyCurrentRow = Worksheets("Sheet1").Range("A:A").SpecialCells(xlCellTypeLastCell).Row
MyCurrentRow comes now back as 1, and I can just count from there. When I did not assign a value into UsedRange, that LastCell value did not reset. No Save required.
I've used Jeeped solution and worked for me when i add .Activate, so:
With Worksheets("Sheet1")
Debug.Print .UsedRange.Address(0, 0)
.UsedRange.Clear
.UsedRange
.Activate
Debug.Print .UsedRange.Address(0, 0)
End With
I'm using Excel2013
This works for me in Excel 2010:
Worksheets("Sheet1").UsedRange.Clear
Worksheets("Sheet1").UsedRange.Calculate