Application.ScreenUpdating = False
Dim j As Integer
Dim E As Range
Dim xragne, yrange, wrange As Range
Set E = Sheets("未入款").Range("e2")
Application.DisplayAlerts = False
Do While E <> ""
j = 1
If E.Offset(j) = E Then
If E.Offset(, 1) = E.Offset(j, 1) Then
If E.Offset(, 34) <> E.Offset(j, 34) Then
If yrange Is Nothing Then Set yrange = E
If wrange Is Nothing Then Set wrange = E.Offset(1)
Set yrange = Union(yrange, E)
Set wrange = Union(wrange, E.Offset(1))
End If
End If
Else
If E(1).Offset(, 34) = "付款確認" Then
If xragne Is Nothing Then Set xragne = E
Set xragne = Union(xragne, E)
End If
End If
Set E = E.Offset(1)
j = j + 1
Loop
If Not xragne Is Nothing Then xragne.EntireRow.Delete
If Not yrange Is Nothing Then yrange.EntireRow.Delete
If Not wrange Is Nothing Then wrange.EntireRow.Delete
End Sub作者: GBKEE 時間: 2014-8-12 06:46
版主:問題是解決了,但我找了一些關於字典物件的資料,我有點搞不太懂,可以幫我開示嗎
幫我解惑下面這段嗎
Option Explicit
Sub Ex()
Dim Rng As Range, d As Object, i As Variant, A As String
Set d = CreateObject("scripting.dictionary")
Set Rng =工作表1.Range("a1").CurrentRegion
For i = 2 To Rng.Rows.Count
A = Rng(i, 1) & "-" & Rng(i, 2)
If d.EXISTS(A) Then '字典物件的(key值)存在傳回True
Set d(A) = Union(Rng.Rows(i), d(A)) ==========??
Else
Set d(A) = Rng.Rows(i) ==========??
End If
Next
For Each i In d.KEYS ==========??
If d(i).Rows.Count = 1 And InStr(d(i).Cells(3), "取消") = 0 Then
d(i).Delete xlUp
ElseIf d(i).Rows.Count > 1 Or d(i).Areas.Count > 1 Then
d(i).Delete xlUp
Dim Rng As Range, d As Object, i As Variant, A As String
Set d = CreateObject("scripting.dictionary")
Set Rng = 工作表1.Range("a1").CurrentRegion
For i = 2 To Rng.Rows.Count
A = Rng(i, 1) & "-" & Rng(i, 2)
If d.EXISTS(A) Then '字典物件的(key值)存在傳回True
Set d(A) = Union(Rng.Rows(i), d(A)) ' ==========??
Else
Set d(A) = Rng.Rows(i) '==========??
End If
MsgBox d(A).Address
Next
For Each i In d.KEYS '==========??
MsgBox i
If d(i).Rows.Count = 1 And InStr(d(i).Cells(3), "取消") = 0 Then
d(i).Delete xlUp
ElseIf d(i).Rows.Count > 1 Or d(i).Areas.Count > 1 Then
d(i).Delete xlUp
End If
Next
End Sub
複製代碼
作者: Andy2483 時間: 2023-4-19 16:30
謝謝論壇,謝謝各位前輩
後學藉此帖練習陣列與字典,學習方案如下,請各位前輩指教
執行前:
[attach]36190[/attach]
執行結果:
[attach]36191[/attach]
Option Explicit
Sub TEST()
Dim Brr, Y, R&, i&, j&, TT, T1$, T2$, T3$, xR As Range
Set Y = CreateObject("Scripting.Dictionary")
Set xR = Range([C2], Cells(Rows.Count, "A").End(3)): Brr = xR
For i = 1 To UBound(Brr)
T1 = Brr(i, 1): T2 = Brr(i, 2): T3 = Brr(i, 3): TT = T1 & "|" & T2
If Y(TT) <> "成功" Then Y(TT) = T3: Y(TT & "|r") = i
Next
For Each TT In Y.keys
If TT Like "*|r" Or Y(TT) = "成功" Then GoTo i00
R = R + 1: For j = 1 To 3: Brr(R, j) = Brr(Y(TT & "|r"), j): Next
i00: Next
If R = 0 Then GoTo i01
xR.Offset(1, 0).ClearContents: xR.Resize(R, 3) = Brr
i01: Set Y = Nothing: Set xR = Nothing: Erase Brr
End Sub