下列二個程式只有列11有差異,其餘都相同。 A區和B區的【任一列】對應列交集值=C區~同欄&不限同欄
Private Sub CommandButton1_Click()
Dim b As Range, RW, R(1 To 3) As Range, UR(1 To 3) As Range, x%, z%, i%, U%
With Sheets(2)
Sheets(1).Range("J7", "P" & Sheets(2).[R6] + 5).Copy .[J7]
Application.Goto .Range("T7:T" & .[R7].End(xlDown).Row) '不用Select,直接跳選目標區
For Each b In Selection
If b <> "" Then
If .Range("R" & b.Row) < .[T5] And .Range("R" & b.Row) - 4 > 0 Then
RW = Array(b(1, -1), .[T5], .[R6]) '列11
For x = 1 To 4
For i = 1 To 3: Set UR(i) = Nothing: Next
For z = 1 To 7
Set R(1) = .[J6].Cells(RW(0) - x + 1, z): U = 0
For i = 2 To 3
Set R(i) = Nothing
'Set R(i) = .[J6:P6].Offset(RW(i - 1) - x, 0).Find(R(1), Lookat:=xlWhole) '不同欄
'If Not R(i) Is Nothing Then U = U + i '不同欄
Set R(i) = .[J6:P6].Cells(RW(i - 1) - x + 1, z) '同欄
If R(i) = R(1) Then U = U + i '同欄
Next i
If U = 2 Then Set UR(1) = Nothing: Exit For
If U = 5 Then
For i = 1 To 3
If UR(i) Is Nothing Then Set UR(i) = R(i) Else Set UR(i) = Union(UR(i), R(i))
Next i
End If
Next z
If Not UR(1) Is Nothing Then
For i = 1 To 3
For Each R(1) In UR(i): R(1).Interior.ColorIndex = Array(8, 4, 6)(i - 1): Next
Next i
End If
Next x
End If
End If
Next b
.[A1].Select
End With
End Sub
C區和B區的【任一列】對應列交集值=A區~同欄&不限同欄
Private Sub CommandButton1_Click()
︰
︰
︰ RW = Array(.[R6], .[T5], b(1, -1))'列11
︰
︰
︰
End Sub
RW = Array(b(1, -1), .[T5], .[R6])
SW = Array(.[R6], .[T5], b(1, -1))
For x = 1 To 4
For i = 1 To 3: Set UR(i) = Nothing: Next
For z = 1 To 7
Set R(1) = .[J6].Cells(RW(0) - x + 1, z): U = 0
Set H(1) = .[J6].Cells(SW(0) - x + 1, z): V = 0
For i = 2 To 3
Set R(i) = Nothing
Set R(i) = .[J6:P6].Cells(RW(i - 1) - x + 1, z) '同欄
If R(i) = R(1) Then U = U + i '同欄
Set H(i) = Nothing
Set H(i) = .[J6:P6].Cells(SW(i - 1) - x + 1, z)
If H(i) = H(1) Then V = V + i
Next i
If U = 2 Or V = 2 Then Set UR(1) = Nothing: Exit For
If U = 5 And V = 5 Then
For i = 1 To 3
If UR(i) Is Nothing Then Set UR(i) = R(i) Else Set UR(i) = Union(UR(i), R(i))
Next i
End If
Next z
If Not UR(1) Is Nothing Then
For i = 1 To 3
For Each R(1) In UR(i): R(1).Interior.ColorIndex = Array(8, 4, 6)(i - 1): Next
Next i
End If
Next x作者: Airman 時間: 2016-1-30 07:18