Excel VBA - 返回一列中未找到的值列表


-1

我想让Excel VBA在消息框提示符中返回列中的所有项目 一个 工作表 Mastersheet 但不在列中 一个 工作表 DeliverySheet

找出这个有很多麻烦,这是我到目前为止所得到的:

Private Sub CommandButton5_Click()

    Dim DeliveryName As Range
    Dim MasterName As Range
    Dim MasterSheet As Worksheet
    Dim DeliverySheet As Worksheet
    Dim valueToFind

    Set MasterSheet = Sheets("Delivery Master List Drop")
    Set DeliveryName = Sheets("For Delivery").Range(Sheets("For Delivery").Cells("A:A"))
    Set MasterName = Sheets("Delivery Master List Drop").Range(Sheets("Delivery Master List Drop").Cells("A:A"))

    For i = 3 To 3000
        valueToFind = DeliveryName("i,1")

        For Each MasterName In MasterSheet
            If Not MasterName.Cells = valueToFind Then
                MsgBox "The following name is not found in the Delivery Master List" & DeliveryName(i, 1).Value, vbExclamation
            End If
        Next MasterName
    Next i
End Sub

我最好希望消息框返回列表中未找到的所有项目(也不一定是(“”)的值),该列表在宏完成后显示。现在我只想让它甚至返回一个值。


1
即使在编辑后我也不确定你要做什么。问题出在哪里?这是一个Q& A网站,虽然我得到了你遇到问题的问题,但我没有看到问题。
YetAnotherRandomUser

使用辅助列可以更容易。你把一个公式放在其中一个表格中 =IF(A1='For Delivery'!A1,0,1) 那么你可以看一下1列的那一列并输出你对该行所需的任何内容。您甚至可以隐藏列,以便用户看不到您的支票。
HackSlash

Answers:


0
Sub SearchForDeliveryItems()

    Dim wksMaster As Worksheet, wksSearch As Worksheet
    Dim rngMaster As Range, rngSearch As Range

    Set wksMaster = Sheets("Delivery Master List Drop")
    Set wksSearch = Sheets("For Delivery")

    With wksMaster
        Set rngMaster = .Range("A1:A" & .Range("A1").SpecialCells(xlCellTypeLastCell).Row)
    End With

    With wksSearch
        Set rngSearch = .Range("A1:A" & .Range("A1").SpecialCells(xlCellTypeLastCell).Row)
    End With

    With rngMaster
        For Each cll In rngSearch
            Set c = .Find(cll.Value2, LookIn:=xlValues)
            If c Is Nothing Then
                MsgBox cll.Value2 & " not found in the Delivery Master List."
            End If
        Next
    End With

End Sub

工作代码总是很棒,但是,在这里,我们更喜欢包含某种解释的答案。环顾四周,看看投票得分最高的答案 - 你会看到Imean。
Scott
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.