我已按以下方式定义了一系列范围。
Dim ColLen, ColLenArr As Long
Dim Address, arrears, TotalRent, TenType, Contract, Advance, Start, DueDate, HbDate, TenDate, PayedFull, CounterVar As Range
Dim PropArrear, TenArrearPayed, DavArrearPayed, DateArrearPayed, OweDavis, OweLandlord As Range
Dim r As Long
Dim MainTable As Variant
Dim ArrearTable As Variant
Dim FirstCellCol, FirstCellRow, FirstCellRowArr, FirstCellColArr
'Initializations
'Intitialization of reference values
FirstCellRow = Range("Address").Cells(1, 1).Row ' first row of Main Table
FirstCellCol = Range("Address").Cells(1, 1).Column ' firt Column of Main Table
MainTable = Array(Address, arrears, TotalRent, TenType, Contract, Advance, Start, DueDate, HbDate, TenDate, PayedFull)
ArrearTable = Array(PropArrear, TenArrearPayed, DavArrearPayed, DateArrearPayed, OweDavis, OweLandlord)
MainArrayLength = UBound(MainTable) - LBound(MainTable) + 1 'Number of elements in MainTable Array
ArrearArrayLength = UBound(ArrearTable) - LBound(ArrearTable) + 1 ' Number of elements in ArrearTable Array
ColLen = Range("Address").Rows.Count ' length of column in rows.
ColLenArr = Range("PropArrear").Rows.Count
FirstCellRowArr = Range("PropArrear").Row
FirstCellColArr = Range("PropArrear").Column
For r = 0 To MainArrayLength - 1 ' For each element in the Array, assign a range
Set MainTable(r) = Range(Cells(FirstCellRow, FirstCellCol + r), Cells(ColLen + FirstCellRow - 1, FirstCellCol))
Next
For r = 0 To ArrearArrayLength - 1 ' For each element index in the Array, assign a range variable
Set ArrearTable(r) = Range(Cells(FirstCellRowArr, FirstCellColArr + r), Cells(ColLenArr + FirstCellRowArr - 1, FirstCellColArr)) ' set a range for each range variable.
Next
我可以通过以下语句访问MainTable()
的'arrear'元素吗?
MainTable(“arrear”)而不是MainTable(1)
谢谢