Dim housetypes, elements, NumRowsElements, NumColumnsHousetypes
elements = Range("c10:c19")
housetypes = Range("d9:n9")
NumRowsElements = UBound(elements)
NumColumnsHousetypes = UBound(housetypes)
MsgBox ("NumRowsElements is " & NumRowsElements & " NumColumnsHousetypes is " & NumColumnsHousetypes)
我不確定為什么上面的代碼會顯示正確數量的行標題(C10 到 C19),但不回傳正確數量的列標題(D9 到 N9)?
uj5u.com熱心網友回復:
兩個elements和housetypes是2D陣列,而不是一維。第一個維度對應于行,第二個維度對應于列。
使用時Ubound,如果省略維度(第二個引數),1則假定。
NumRowsElements = UBound(elements, 1)
NumColumnsHousetypes = UBound(housetypes, 2)
將回傳您想要的結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/357731.html
