-2

我从互联网上得到了这个 vba:

Sub MatchCompanyName_InsertContact_EmailAddress()
    Dim hold As New Collection

    For Each celli In Columns(6).Cells
        On Error GoTo raa
        If Not celli.Value = Empty Then
            hold.Add Item:=celli.Row, key:="" & celli.Value
        End If
    Next celli

    On Error Resume Next
    raa:
    Range("J1:L1").Offset(celli.Row - 1, 0).Value = Range("J1:L1").Offset(hold(celli.Value) - 1, 0).Value
    Resume Next
End Sub

代码查找和替换顺序是从上到下,我需要它是相反的。

4

1 回答 1

0

您需要反转收藏中的项目。一种方法是添加一个新集合并以相反的顺序传输,如下所示:

raa:

Dim newHold as New Collection
For Each obj in hold
    If newHold.Count > 0 Then
        newHold.Add item := obj, before := 1
    Else
        newHold.Add item := obj
    End If
Next

Range("J1:L1").Offset(celli.Row - 1, 0).Value = Range("J1:L1").Offset(newHold(celli.Value) - 1, 0).Value
于 2013-10-14T18:47:02.880 回答