[英]how to use Application.WorksheetFunction.CountA to count sheets from 1 to 31
[英]EXCEL VBA - how to pass # of filled cells inside a custom range, into the “i” variable using Application.WorksheetFunction.CountA?
我需要為“ i”變量分配一個數字。 此#應該是Worksheets("Offset").Range("AN20:AN3000")
中已填充單元格的數量
是-在這種情況下,“偏移”是圖紙的名稱。 這正是我真正需要的。 在上述范圍內,有171個填充的單元格,我需要將該數字分配給“ i”變量。 最好是,我想使用Application.WorksheetFunction.CountA
來實現
這就是我自己編寫的代碼
Sub celebrities_height_into_array()
' declare an array to hold celebrities height
Dim height_array() As Integer
Dim height_range As Range
Dim i As Integer
Set height_range = ThisWorkbook.Worksheets("Offset").Range("AN20:AN3000")
' I keep celebrities height in this range, in centimeters.
i = Application.WorksheetFunction.CountA(Range(height_range))
End Sub
稍后,我將所有高度加載到數組中。 這是我使用WorksheetFunction.CountA所讀到的內容
您唯一的錯誤是多余的Range(
請嘗試以下代碼。 它應該工作。
Sub celebrities_height_into_array()
' declare an array to hold celebrities height
Dim height_array() As Integer
Dim height_range As Range
Dim i As Integer
Set height_range = ThisWorkbook.Worksheets("Offset").Range("AN20:AN3000")
' I keep celebrities height in this range, in centimeters.
i = Application.WorksheetFunction.CountA(height_range)
End Sub
height_range已被定義為范圍。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.