Amount of rows in sheet

前端 未结 2 574
情歌与酒
情歌与酒 2021-02-07 11:58

Goal:
A variable should contain amount of rows from a specific sheet.

Problem:
What syntax code in Excel VBA do I need to count amount of rows from sheet?

2条回答
  •  广开言路
    2021-02-07 12:47

    You can also try:

    i = Sheets("SheetName").UsedRange.Rows.Count
    

    However, this can get a little buggy if you start deleting and clearing rows.

    A better way to do this is:

    i = Cells(Sheets("SheetName").Rows.Count, 1).End(xlup).Row
    

    This assumes that each row has data in column 1.

提交回复
热议问题