喜歡使用Cells(1, 1)
,而不是Range("A1")
,有什麼用/列索引範圍在VBA的最佳方式?如何使用列/行索引範圍在VBA
我想出了兩個解決方法來表示範圍( 「A:A」):
Range(Cells(1, 1), Cells(Columns(1).Rows.count, 1))
Union(Columns(1), Columns(1))
有沒有更好更簡潔的解決方案?
編輯:注意到Tehscript的迴應,並感謝相同。我已經嘗試過,但它給下面的錯誤:
Run-time error '13': Type mismatch.
下面的代碼:
Sub tfind()
Dim r1 As Range
Set r1 = Columns(1)
MsgBox mCount("Test:", r1)
End Sub
Function mCount(find As String, lookin As Range) As Long
Dim cell As Range
For Each cell In lookin
If (Left(cell.Value, Len(find)) = find) Then mCount = mCount + 1
Next
End Function
雖然它工作正常,如果3號線:
Set r1 = Columns(1)
改爲:
Set r1 = Union(Columns(1), Columns(1))
如果你已經張貼你的代碼前面,它會更容易得到正確的答案。你所尋找的是'.Cells' – Tehscript
完美! thanx再次 – curious