以下是引用tycp在2007-11-28 17:29:10的发言:用二维数组做的,比一维数组快很多!
Dim p As Integer, pp As Integer
Dim jxgz() As String, sf() As String
Sub check()
Dim m As Integer
Dim arr
Dim s1 As Integer, s2 As String
Dim over() As Boolean, over1() As Boolean
Dim box() As Integer
With Worksheets("数据")
p = .Range("a65536").End(xlUp).Row
arr = .Range("a2:c" & p)
End With
m = UBound(arr, 1)
ReDim over(1 To m) As Boolean
ReDim over1(1 To m) As Boolean
ReDim jxgz(1 To m) As String
ReDim sf(1 To m) As String
'提取不重复的机型故障-----------------------------------------------------------
p = 0
For i = 1 To m
If over(i) = False Then
p = p + 1
jxgz(p) = Trim(arr(i, 2)) & Trim(arr(i, 3))
over(i) = True
For j = 1 To m
If i <> j And over(j) = False Then
src = Trim(arr(i, 2)) & Trim(arr(i, 3))
des = Trim(arr(j, 2)) & Trim(arr(j, 3))
If src = des Then
over(j) = True
End If
End If
Next
End If
Next
'提取不重复的省份---------------------------------------------------------------
pp = 0
For i = 1 To m
If over1(i) = False Then
pp = pp + 1
sf(pp) = Trim(arr(i, 1))
over1(i) = True
For j = 1 To m
If i <> j And over1(j) = False Then
src = Trim(arr(i, 1))
des = Trim(arr(j, 1))
If src = des Then
over1(j) = True
End If
End If
Next
End If
Next
ReDim box(1 To p, 1 To pp + 1) As Integer
For i = 1 To m
s1 = findnum(Trim(arr(i, 2)) & Trim(arr(i, 3)), True)
box(s1, pp + 1) = box(s1, pp + 1) + 1
s1 = findnum(Trim(arr(i, 2)) & Trim(arr(i, 3)), True)
s2 = findnum(Trim(arr(i, 1)), False)
box(s1, s2) = box(s1, s2) + 1
Next
Range("d2").Resize(p, pp + 1) = box
End Sub
Function findnum(str As String, flag As Boolean) As Integer
Dim i As Integer
If flag = True Then
For i = 1 To p
If jxgz(i) = str Then
findnum = i
Exit For
End If
Next
Else
For i = 1 To pp
If sf(i) = str Then
findnum = i
Exit For
End If
Next
End If
End Function
试了一下,和题目要求有点不一样.