Excel resetting “UsedRange”

前端 未结 12 2064
醉酒成梦
醉酒成梦 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 16:03

    Thanks to Claus for having the correct answer, but it is incomplete, and he completed it with a comment on the main post. I'll answer here to combine the useful bits into a single working solution.

    Note: I have not tried variations to see which steps are necessary, but these steps work to clear unnecessary used range.

    Sub ResetUsedRange()
    dim rngToDelete as range
    
    set rngToDelete = 'Whatever you want
    
    rngToDelete.EntireRow.Clear
    rngToDelete.EntireRow.Select
    Selection.Delete Shift:=xlUp
    
    ActiveWorkbook.Save 'This step has been stated to be necessary for the range to reset.
    
    End Sub
    

提交回复
热议问题