尽我所能我无法纠正超出范围的"下标"当我尝试使用Redim Preserve扩展数组的大小时,下面的代码抛出下面的代码的错误。关于可能出错的任何想法?
Sub Demo()
'Set Excel variables
Dim wb As Workbook: Set wb = ActiveWorkbook
Dim wsCluster As Worksheet: Set wsCluster = wb.Worksheets("Cluster")
Dim initialK As ListObject: Set initialK = wsCluster.ListObjects("k")
'Set Array variables
Dim kArray() As Variant
ReDim kArray(1 To initialK.DataBodyRange.Rows.Count, 1 To initialK.DataBodyRange.Columns.Count)
kArray = initialK.DataBodyRange
'Set Other variables
Dim coordResults As Variant, kResults As Variant, addKs As Variant, dupeArray As Variant
Dim transferLat As Double, transferLong As Double, potDupeCount As Long, expandK As Long, nextAvailK As Long
'Run the assignment function once, then loop through average/assign functions
coordResults = Assign(coordArray, kArray)
For i = 1 To 3
kResults = Average(coordArray, kArray, coordResults)
coordResults = Assign(coordArray, kArray)
Next i
'Run the radius function
addKs = AdjustForRadius(coordArray, kResults, coordResults)
'Add the new, deduped centroid data to the kResults array
expandK = UBound(addKs, 1) + UBound(kArray, 1)
ReDim Preserve kArray(1 To expandK, 1 To 3)
End Sub
功能正常。 "扩展"变量很好。
我测试了我所知道的一切。
杰克