Private Sub a()
Dim toAdd As Boolean, uniqueNumbers As Integer, i As Integer, j As Integer, z As Integer
z = 1
Cells(1, 3).Value = z
Cells(1, 4).Value = Cells(1, 1).Value
uniqueNumbers = 1
toAdd = True
For i = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For j = 1 To uniqueNumbers
If Cells(i, 1).Value = Cells(j, 4).Value Then
toAdd = False
End If
Next j
If toAdd = True Then
z = z + 1
Cells(uniqueNumbers, 3).Value = z
Cells(uniqueNumbers, 4).Value = Cells(i, 1).Value
uniqueNumbers = uniqueNumbers '+ 1
End If
toAdd = True
uniqueNumbers = uniqueNumbers + 1
Next i
End Sub
Private Sub b()
Dim toAdd As Boolean, uniqueNumbers As Integer, i As Integer, j As Integer, z As Integer, s As Integer, a As String, k As Integer
z = 1
j = 1
s = 1
k = 1
a = Cells(1, 4).Value
Cells(1, 5).Value = z
Cells(1, 6).Value = Cells(1, 2).Value
uniqueNumbers = 1
toAdd = True
For i = 1 To ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For j = k To uniqueNumbers
'If j = 2800 Then Stop
'If Cells(i, 2).Value = Cells(j, 6).Value And a = Cells(i, 1).Value Then
If Cells(i, 2).Value = Cells(j, 6).Value And a = Cells(i, 1).Value Then
toAdd = False
End If
Next j
If toAdd = True Then
If Cells(uniqueNumbers, 4).Value = "" Then
z = z + 1
Cells(uniqueNumbers, 5).Value = z
Else
a = Cells(i, 4).Value
k = i
z = 1
Cells(uniqueNumbers, 5).Value = z
End If
Cells(uniqueNumbers - s + 1, 7).Value = s - 1
Cells(uniqueNumbers, 6).Value = Cells(i, 2).Value
uniqueNumbers = uniqueNumbers '+ 1
s = 1
End If
toAdd = True
uniqueNumbers = uniqueNumbers + 1
s = s + 1
If i = 666 Then Stop
Next i
End Sub
我不知道該怎麼辦。採集?或其他方式 – plzfixme
我正在嘗試編寫vba代碼。我無法找到排序算法我的問題 – plzfixme
您可以將它們存儲爲2維數組。然後做一個項目重複的次數。這將是一個辦法。或者您可以計算A列中的值出現次數。然後做一個計數,如果對B列的值從你從A列值的計數得到的範圍內進行計數。 – Sam