Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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
Excel 我想使用命令按钮在活动工作表的textbox2中搜索/查找值_Excel_Vba - Fatal编程技术网

Excel 我想使用命令按钮在活动工作表的textbox2中搜索/查找值

Excel 我想使用命令按钮在活动工作表的textbox2中搜索/查找值,excel,vba,Excel,Vba,我想使用命令按钮在活动工作表的textbox2中搜索/查找值 这是我的密码: Dim ws As Worksheet Set ws = Worksheets("FSS-TEM-00025") Dim FindString As String Dim Rng As Range FindString = Me.TextBox2.Value If Trim(FindString) <> "" Then With ws.Range("A1:Z1

我想使用命令按钮在活动工作表的textbox2中搜索/查找值

这是我的密码:

Dim ws As Worksheet
Set ws = Worksheets("FSS-TEM-00025")
Dim FindString As String
    Dim Rng As Range    
    FindString = Me.TextBox2.Value
    If Trim(FindString) <> "" Then
        With ws.Range("A1:Z1048576")
            'Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)'
             Set Rng = ws.Cells.Find(What:=FindString, SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

            If Not Rng Is Nothing Then
                Application.Goto Rng, True
            Else
                MsgBox "Nothing found"
            End If
        End With
    End If


     Unload Me
Dim ws As工作表
设置ws=工作表(“FSS-TEM-00025”)
作为字符串的暗FindString
变暗Rng As范围
FindString=Me.TextBox2.Value
如果修剪(FindString)“,则
带ws.范围(“A1:Z1048576”)
'Set Rng=.Find(What:=FindString_
之后:=.Cells(.Cells.Count)_
LookIn:=xlValues_
看:=xlother_
搜索顺序:=xlByRows_
SearchDirection:=xlNext_
匹配案例:=False)'
设置Rng=ws.Cells.Find(What:=FindString,SearchOrder:=xlRows_
SearchDirection:=xlPrevious,LookIn:=xlValues)。行+1
如果不是,那么Rng什么都不是
应用程序。转到Rng,对
其他的
MsgBox“未找到任何内容”
如果结束
以
如果结束
卸下我

试试这个。这对我有用

Option Explicit

Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim FindString As String
    Dim Rng As Range

    Set ws = ThisWorkbook.Worksheets("FSS-TEM-00025")

    FindString = TextBox2.Value

    If Trim(FindString) <> "" Then
        Set Rng = ws.Cells.Find( _
                         What:=FindString, _
                         LookIn:=xlValues, _
                         LookAt:=xlPart, _
                         SearchOrder:=xlByRows, _
                         SearchDirection:=xlNext, _
                         MatchCase:=False, _
                         SearchFormat:=False)

        If Not Rng Is Nothing Then
            Application.Goto Rng, True
        Else
            MsgBox "Nothing found"
        End If
    End If
End Sub
选项显式
私有子命令按钮1_单击()
将ws设置为工作表
作为字符串的暗FindString
变暗Rng As范围
设置ws=ThisWorkbook.工作表(“FSS-TEM-00025”)
FindString=TextBox2.Value
如果修剪(FindString)“,则
Set Rng=ws.Cells.Find(_
什么:=查找字符串_
LookIn:=xlValues_
看:=xlPart_
搜索顺序:=xlByRows_
SearchDirection:=xlNext_
MatchCase:=假_
SearchFormat:=False)
如果不是,那么Rng什么都不是
应用程序。转到Rng,对
其他的
MsgBox“未找到任何内容”
如果结束
如果结束
端接头
如果您试图找到完整的匹配项,请将
LookAt:=xlPart
更改为
LookAt:=xlother


有关
的详细信息。查找

试试这个。这对我有用

Option Explicit

Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim FindString As String
    Dim Rng As Range

    Set ws = ThisWorkbook.Worksheets("FSS-TEM-00025")

    FindString = TextBox2.Value

    If Trim(FindString) <> "" Then
        Set Rng = ws.Cells.Find( _
                         What:=FindString, _
                         LookIn:=xlValues, _
                         LookAt:=xlPart, _
                         SearchOrder:=xlByRows, _
                         SearchDirection:=xlNext, _
                         MatchCase:=False, _
                         SearchFormat:=False)

        If Not Rng Is Nothing Then
            Application.Goto Rng, True
        Else
            MsgBox "Nothing found"
        End If
    End If
End Sub
选项显式
私有子命令按钮1_单击()
将ws设置为工作表
作为字符串的暗FindString
变暗Rng As范围
设置ws=ThisWorkbook.工作表(“FSS-TEM-00025”)
FindString=TextBox2.Value
如果修剪(FindString)“,则
Set Rng=ws.Cells.Find(_
什么:=查找字符串_
LookIn:=xlValues_
看:=xlPart_
搜索顺序:=xlByRows_
SearchDirection:=xlNext_
MatchCase:=假_
SearchFormat:=False)
如果不是,那么Rng什么都不是
应用程序。转到Rng,对
其他的
MsgBox“未找到任何内容”
如果结束
如果结束
端接头
如果您试图找到完整的匹配项,请将
LookAt:=xlPart
更改为
LookAt:=xlother


有关
.Find

的详细信息问题在于,单击按钮时,在活动工作表中找不到在textbox2中输入的值问题在于,单击按钮时,在活动工作表中找不到在textbox2中输入的值