Excel resetting “UsedRange”

前端 未结 12 2152
醉酒成梦
醉酒成梦 2021-01-05 15:42

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

12条回答
  •  情歌与酒
    2021-01-05 15:54

    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.

提交回复
热议问题