我的工作是在工作中修复假期电子表格,文件的问题是有直接引用,对其他工作表的间接引用和一些未引用的部分,所以如果你想把人们完全按照不同的顺序排列把整个事情搞砸了。所以,我一直在尝试做的是用人们的名字填充一个数组,对数组进行排序,然后与原始数组交叉引用并找到一个新顺序,以便可以在整个工作表中实施这个新顺序而不会搞砸.
问题是我似乎无法填充数组,我已经查看了此处的其他答案,但我确定我正在正确使用 redim,这往往是问题所在。
因此,Previous 是原始列表,Current 是排序列表,Position 是前一个与当前相关的数字。
Sub Sorting()
Dim Previous() As Variant
Dim Current() As Variant
Dim maxrow As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim Position() As Long
Dim rng As Range
Dim strTemp As String
k = 0
i = 3
maxrow = 3
Do While Worksheets(1).Cells(i, 1).Value <> "STAT.HOL'S (ST)"
maxrow = maxrow + 1
i = i + 1
Loop
maxrow = maxrow - 1
ReDim Previous(0 To maxrow)
ReDim Position(0 To maxrow)
ReDim Current(0 To maxrow)
Previous = Range("a4", Range("a" & maxrow))
Current = Previous
For i = 0 To maxrow
For j = 0 To maxrow
If Current(i) > Current(j) Then
strTemp = Current(i)
Current(i) = Current(j)
Current(j) = strTemp
End If
Next j
Next i
For i = 0 To maxrow
For j = 0 To maxrow
If Previous(i) = Current(j).Value Then
Position(k) = j
k = k + 1
End If
Next j
Next i
End Sub
谢谢你的帮助。艾米