Last Used Cell in sheet

后端 未结 3 870
名媛妹妹
名媛妹妹 2021-01-21 09:59

I\'m new here and I\'m looking to use Excel VBA to return the last used cell in a worksheet.

I\'vv looked at Error in finding last used cell in Excel with VBA) but that d

3条回答
  •  温柔的废话
    2021-01-21 10:18

    Although the answers are very valid, I'd be careful using SpecialCells, CurrentRegion and all those.

    Although they work most of the time, they are not 100% reliable in my experience.

    For example, CurrentRegion will not pick up all data if the data happens to have an empty column or row etc.

    The best Approach, in my opinion is to always use headers with your data. You can then enumerate all headers and find the last used row in that column. You can then determine the greatest row used and now define your data range.

    Btw, if you select the last cell in a specified column then use the Range.End(xlUp) you can quickly determine the last used row for that column without Looping.

提交回复
热议问题