Excel resetting “UsedRange”

前端 未结 12 2066
醉酒成梦
醉酒成梦 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:05

    This is the solution I used.

    Sub CorrectUsedRange()
        Dim values
        Dim usedRangeAddress As String
        Dim r As Range
        'Get UsedRange Address prior to deleting Range
        usedRangeAddress = ActiveSheet.UsedRange.Address
        'Store values of cells to array.
        values = ActiveSheet.UsedRange
        'Delete all cells in the sheet
        ActiveSheet.Cells.Delete
        'Restore values to their initial locations
        Range(usedRangeAddress) = values
    End Sub
    

提交回复
热议问题