简体   繁体   English

Excel VBA-搜索列表和弹出消息

[英]Excel VBA - Search through list and pop-up message

I would like to ask for some help regarding the following problem: I have a workbook with two sheets. 我想就以下问题寻求帮助:我有一本有两张纸的工作簿。 Sheet 2 contains 2 lists with phrases in them and Sheet 1 has some data. 工作表2包含2个带有短语的列表,工作表1包含一些数据。 I want to create a macro that checks the data in Sheet 1 and if it finds a phrase that does not appear in the lists in Sheet 2 it gives a pop-up message. 我想创建一个宏来检查工作表1中的数据,如果它找到一个没有出现在工作表2的列表中的短语,它会弹出消息。 Furthermore, Sheet 1 will contain phrases separated by commas. 此外,工作表1将包含用逗号分隔的短语。 Is it possible to also check that as well? 是否也可以进行检查? (see screenshot) Although really simple, I have worked out the following, however, I am sure the answer is more complicated. (请参见屏幕截图)尽管确实很简单,但是我已经制定了以下解决方案,但是我确信答案会更加复杂。 Any help is appreciated! 任何帮助表示赞赏! Thank you in advance! 先感谢您!

包含数据的表1

带有短语列表的工作表2

My code: 我的代码:

Sub check()
For i = 2 To 2

If Cells(i, "A") <> Worksheets("Sheet2").Cells(i, "B") Then
MsgBox "Phrase 1 does not match"
    End If

For j = 2 To 2
    If Cells(j, "B") <> Worksheets("Sheet2").Cells(j, "C") Then
    MsgBox "Phrase 2 does not match"

End If
Next j
Next i
End Sub

The VBA code should look like this VBA代码应如下所示

For all cells in column 'Phase 1'
 Use the SPLIT() function to split the comma separated values 
 and store them into a list of distinct values

  For all distinct values in the list
     Use the VLOOKUP function on the 'Phrase list 1' column in sheet2, 
     searching for the current value

     If vlookup returns a valid result then
         do nothing
     else
        pop up message
     end if

   end loop of distinct values

end loop of cells in column 'Phase 1'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM