Excel resetting “UsedRange”

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

    Here is how I inserted your code.

        Sheets("Edit Data").Select
    '    Range("A6").Select
    '    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    '    Selection.Delete Shift:=xlUp
    '    ActiveWorkbook.Save
        With Worksheets("Edit Data")
            Debug.Print .UsedRange.Address(0, 0)
            .UsedRange.Clear
            .UsedRange    '<~~ called by itself will reset it
            Debug.Print .UsedRange.Address(0, 0)
        End With
    

    Here is the full used range with data

    Here is the used range after your code executed

    The end of range should be i7 instead it is still i26

    However the code which I commented out does reset range to i7

    From what you are saying just to confirm. My commented out code will only work for Excel 2010 and newer. We have some 2007 versions hanging around. For those the workbook will actually have to be closed and reopened for the range to reset?

    Note- the code examples were executed on version 2016

提交回复
热议问题