簡體   English   中英

Excel vlookup獲取所有出現的單元格詳細信息?

[英]Excel vlookup to get all occurrence cell details?

我正在將數據表單行Data1與Data 2匹配進行自動化

我已經通過循環語句完成了,但是問題是花很多時間,當行數增加時

因此,我計划通過vlookup進行操作,在vlookup中,僅返回第一個出現的單元格,但我需要找到所有匹配的單元格並突出顯示匹配的行,如圖所示。

在此處輸入圖片說明

直接使用單元會降低代碼性能。 嘗試將Data1和Data2設置為數組並使用數組。

像這樣:

With ActiveSheet
    arr = .Range(.[A2], .Cells(.Rows.Count, "A").End(xlUp)).Value
    arr2 = .Range(.[D2], .Cells(.Rows.Count, "D").End(xlUp)).Value

    For i& = 1 To UBound(arr)
        For j& = 1 To UBound(arr2)
            If arr(i, 1) = arr2(j) Then
                ...
            End If
        Next j
    Next i
End With

希望你正在尋找這個

Sub testvlookup()
    Dim lastrow, lastrowdata, incre, i, j As Long
    lastrow = Range("A" & Rows.Count).End(xlUp).Row
    lastrowdata = Range("D" & Rows.Count).End(xlUp).Row
    incre = 6
    For i = 2 To lastrow
        For j = 2 To lastrowdata
            If Range("A" & i).Value = Range("D" & j).Value Then
                Range("D" & j, "G" & j).Interior.ColorIndex = incre
            End If
        Next j
        incre = incre + 1
    Next i
End Sub

在此處輸入圖片說明

我不明白為什么要減少許多行的意義,擁有更多有關此的信息會很好。

我會像其他人一樣做,花費100000次比較需要大約1秒鍾。

Dim i As Integer
Dim b As Integer

i = 1

While i < 20000
Range("A1:A5").Copy Range(Cells(i, 4), Cells(i + 5, 4))
i = i + 5
Wend

MsgBox ("hi")
i = 1
While i < 7
   b = 3
While b < 20000
    If Cells(i, 1).Value = Cells(b, 4).Value Then
        Cells(b, 4).Interior.ColorIndex = i
    End If
b = b + 1
Wend
i = i + 1
Wend
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM