Excel resetting “UsedRange”

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

    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.

提交回复
热议问题