VBA - Range.Row.Count

前端 未结 10 1521
别那么骄傲
别那么骄傲 2020-12-24 13:23

I have written a simple code to illustrate my predicament.

Sub test()
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets(\"Sheet1\")

    Dim k As Lon         


        
10条回答
  •  猫巷女王i
    2020-12-24 13:49

    This works for me especially in pivots table filtering when I want the count of cells with data on a filtered column. Reduce k accordingly (k - 1) if you have a header row for filtering:

    k = Sheets("Sheet1").Range("$A:$A").SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeConstants).Count
    

提交回复
热议问题