Dưới đây là mục của tôi - không nhất thiết phải tốt hơn so với Irwin của
Function GetValue(rInput As Range, Row As Long, Column As Long) As Variant
Dim rArea As Range
Dim lCumRows As Long
Dim lActualRow As Long
For Each rArea In rInput.Areas
lCumRows = lCumRows + rArea.Rows.Count
If Row <= lCumRows Then
lActualRow = rArea.Rows(1).Row + (Row - (lCumRows - rArea.Rows.Count + 1))
Exit For
End If
Next rArea
If lActualRow > 0 Then
GetValue = rInput.Parent.Cells(lActualRow, Column).Value
End If
End Function
Function GetValue2(rInput As Range, Row As Long, Column As Long) As Variant
Dim rRow As Range
Dim lRowCnt As Long
For Each rRow In rInput.Rows
lRowCnt = lRowCnt + 1
If lRowCnt = lrow Then
GetValue2 = rRow.Cells(1, Column).Value
Exit For
End If
Next rRow
End Function
Và đi đọc http://www.dailydoseofexcel.com/archives/2004/07/07/the-strange-object/ đối với một số cái nhìn sâu sắc là tại sao Excel là hành xử theo cách đó.
Và proc kiểm tra nếu bạn quan tâm
Sub test()
Dim myRange As Range
Set myRange = Union(Rows(2), Range("4:205"), Rows(214))
Debug.Print GetValue(myRange, 1, 2), GetValue(myRange, 1, 2)
Debug.Print GetValue(myRange, 2, 2), GetValue(myRange, 2, 2)
Debug.Print GetValue(myRange, 3, 2), GetValue(myRange, 3, 2)
Debug.Print GetValue(myRange, 200, 2), GetValue(myRange, 200, 2)
End Sub
Nguồn
2010-04-02 18:50:37
Jeffrey, bạn nên cân nhắc chọn câu trả lời của riêng bạn hoặc câu trả lời khác bên dưới làm câu trả lời đúng bằng cách nhấp vào dấu kiểm bên cạnh dấu kiểm mà bạn cảm thấy câu trả lời hay nhất cho câu hỏi của mình. –