Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 添加命令单击excel以搜索hello_Vba_Excel_Highlighting - Fatal编程技术网

Vba 添加命令单击excel以搜索hello

Vba 添加命令单击excel以搜索hello,vba,excel,highlighting,Vba,Excel,Highlighting,我正在尝试将搜索命令单击添加到第3页的代码中。我创建了一个命令单击并尝试 其他工作簿,但不起作用。你能告诉我我做错了什么吗, 我是vba的新手,因此任何帮助都将不胜感激 Sub Sample() Dim oRange As Range, aCell As Range, bCell As Range Dim ws As Worksheet Dim ExitLoop As Boolean Dim SearchString As String, FoundAt As String Dim iCount

我正在尝试将搜索命令单击添加到第3页的代码中。我创建了一个命令单击并尝试 其他工作簿,但不起作用。你能告诉我我做错了什么吗, 我是vba的新手,因此任何帮助都将不胜感激

Sub Sample()
Dim oRange As Range, aCell As Range, bCell As Range
Dim ws As Worksheet
Dim ExitLoop As Boolean
Dim SearchString As String, FoundAt As String
Dim iCount() As String
Dim outws As Worksheet
Dim Sheets As String



Set ws = Worksheets("detail_report")

 Sheets("detail_report").Activate
 ActiveSheet.cmdRefresh_Click

Set oRange = ws.Range("CZ:CZ")

SearchString = "input"

Set aCell = oRange.Find(What:=SearchString, LookIn:=xlValues, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)

If Not aCell Is Nothing Then
    Set bCell = aCell
    FoundAt = aCell.Address
    Do While ExitLoop = False
        Set aCell = oRange.FindNext(After:=aCell)

        If Not aCell Is Nothing Then
            If aCell.Address = bCell.Address Then Exit Do
            FoundAt = FoundAt & ", " & aCell.Address
        Else
            ExitLoop = True
        End If
    Loop

     iCount = Split(FoundAt, ", ")

    Set outws = Worksheets("output")

   outws.Range("A2").Value = SearchString

   outws.Range("B2").Value = UBound(iCount) + 1

Else
    MsgBox SearchString & " not Found"

End If

End Sub

您的IF条件可能不符合您的要求。。。。 试着用。。。为了速度/清晰度,以结尾

With Worksheets("detail_report").Range("CZ:CZ")
    aCell = .Find(What:=SearchString, LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False))

    If aCell <> "" Then 'this is probably what you want
        'do your manipulation stuff here
    End if

End With
带工作表(“详细报告”)。范围(“CZ:CZ”)
aCell=.Find(What:=SearchString,LookIn:=xlValues_
查看:=xlPart,搜索顺序:=xlByRows,搜索方向:=xlNext_
匹配案例:=False,搜索格式:=False))
如果是aCell,那么这可能就是您想要的
“在这里做你的操作
如果结束
以

您的IF条件可能没有按您希望的方式运行。。。。 试着用。。。为了速度/清晰度,以结尾

With Worksheets("detail_report").Range("CZ:CZ")
    aCell = .Find(What:=SearchString, LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False))

    If aCell <> "" Then 'this is probably what you want
        'do your manipulation stuff here
    End if

End With
带工作表(“详细报告”)。范围(“CZ:CZ”)
aCell=.Find(What:=SearchString,LookIn:=xlValues_
查看:=xlPart,搜索顺序:=xlByRows,搜索方向:=xlNext_
匹配案例:=False,搜索格式:=False))
如果是aCell,那么这可能就是您想要的
“在这里做你的操作
如果结束
以

“……但它不起作用。”它怎么不起作用?你有错误吗?宏是否运行,但什么也没有发生?请描述它是如何不像您期望的那样工作的。它运行但没有发生任何事情删除您的错误行,运行它并查看它是否中断。然后让我们知道停止时突出显示的行。您发布的代码无法编译,因为标签
Err
未定义。@Scott-您在哪里看到错误行?还是被删掉了?“……但没用。”怎么没用?你有错误吗?宏是否运行,但什么也没有发生?请描述它是如何不像您期望的那样工作的。它运行但没有发生任何事情删除您的错误行,运行它并查看它是否中断。然后让我们知道停止时突出显示的行。您发布的代码无法编译,因为标签
Err
未定义。@Scott-您在哪里看到错误行?还是被删掉了?