|
2#
楼主 |
发表于 2008-2-2 15:19:58
|
只看该作者
各位大侠,小弟有一数组例子,但SHEET2显示不了数据,各位有VBA编的方法请帮忙!
Private Sub Worksheet_Activate()
Dim i As Integer, d As Variant
Dim TotCount As Integer
Sheet2.Activate
Cells.ClearContents
TotCount = Sheet1.Range("A65530").End(xlUp).Row
j = 2
With Sheet1
.Columns("G:G").ClearContents
For i = 2 To 5
.Columns("G:G").ClearContents
.Range("A2:F" & TotCount).Sort key1:=.Range("A2"), key2:=.Cells(2, i)
.Range("G2:G" & TotCount).FormulaR1C1 = "=IF(OR(AND(RC[-6]=R[-1]C[-6],RC[-" & 7 - i & "]=R[-1]C[-" & 7 - i & "],RC[-" & 7 - i & "] <> """"),AND(RC[-6]=R[1]C[-6],RC[-" & 7 - i & "]=R[1]C[-" & 7 - i & "],RC[-" & 7 - i & "] <> """")),1,"""")"
d = .Range("G2:G" & TotCount): .Range("G2:G" & TotCount) = d
.Range("A2:G" & TotCount).Sort key1:=Sheet1.Range("G2")
d = .Range("G65530").End(xlUp).Row
If .Range("G2" & d) = 1 Then
.Range("A2:F" & d).Copy Range("A" & j & ":F" & j + d - 1)
j = j + d
End If
Next i
.Columns("G:G").ClearContents
End With
End Sub |
|