【发布时间】:2017-11-09 20:49:13
【问题描述】:
为此苦苦挣扎。我有一个输入框弹出。然后在一系列单元格中搜索输入的值。如果找到,它会设置特定的值。但是,我希望它显示一个 msgbox,然后如果在该范围内找不到该值,则结束 sub。无论我尝试什么,我都无法让它发挥作用。如果“不等于”的代码不存在,只要输入的值与范围内的值匹配,它就可以正常工作。当我添加“不等于”的代码时,它会启动 msgbox 并结束 sub,但无论找到的值如何,都会这样做。据我所知,应该是其中之一。如果匹配,则继续。如果没有,它就结束了。但这并没有发生。我在这里有什么问题?谢谢
Sub Test()
Dim aOutlook As Object
Dim aEmail As Object
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
Dim strbox As String
Dim stritem As String
Dim x As Long
Dim r As Long
Dim lr, lookRng As Range
Dim findStr As String
Dim foundCell As Variant
Dim foundcell1 As Variant
Dim foundcell2 As Variant
Dim strbody As String
Dim sigstring As String
Dim signature As String
Dim findstr1 As String
Dim foundrng As Range
Dim findrange As String
Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)
findstr1 = InputBox("Enter Email Address")
findStr = InputBox("Enter the name to find")
lr = Cells(Rows.Count, "a").End(xlUp).Row
Set lookRng = Range("B1:B" & lr)
For x = 1 To lr
If Range("a" & x).Value = findStr Then
Set foundCell = Range("B" & x).Offset(0, 4)
Set foundcell1 = Range("B" & x).Offset(0, 1)
Set foundcell2 = Range("B" & x).Offset(0, 5)
End If
Next x
For r = 1 To lr
If Range("a" & r).Value <> findStr Then
MsgBox "Is case-sensitive", vbExclamation, "No Match!"
Exit Sub
End If
Next r
【问题讨论】:
-
您能否在“不等于”行设置断点并检查正在比较的值?对循环中的每个步骤执行此操作。