簡體   English   中英

希望添加150個值以在此語句內搜索:::如果Cell.Value =“ 5”,則

[英]Looking to add 150 values to search for within this statement::: If Cell.Value = “5” Then

我需要根據在J列中找到的值列表來收集大量數據。對於150個左右的限定值,我希望將整行復制到工作簿中的另一張紙上。 這使我接近,但不確定如何添加150個左右的值來查找:

 For Each Cell In Sheets(1).Range("J:J")`enter code here`
If Cell.Value = "ABCDEFG" Then
    matchRow = Cell.Row
    Rows(matchRow & ":" & matchRow).Select
    Selection.Copy

    Sheets("Sheet2").Select
    ActiveSheet.Rows(matchRow).Select
    ActiveSheet.Paste
    Sheets("Sheet1").Select
End If
Next

使用Match()的示例

Sub Tester()

    Dim c As Range, rngTest As Range, rngList As Range

    Set rngList = ThisWorkbook.Sheets("list").Range("A1:A150")

    Set rngTest = Application.Intersect(Sheets(1).Range("J:J"), Sheets(1).UsedRange)

    If Not rngTest Is Nothing Then        
       For Each c In rngTest
            'Does the value in c match any of the values in the
            '   list on sheet "list" range A1:A150 ?
            'If Yes (Match does not return an error) then copy that row
            If Not IsError(Application.Match(c.Value, rngList, 0)) Then
                c.EntireRow.Copy Sheets("Sheet2").Cells(c.Row, 1)
            End If
        Next
    End If

End Sub

暫無
暫無

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

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