1

コマンドボタンを使用して、アクティブなシートの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
4

1 に答える 1

1

これを試して。これは私のために働く

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

完全な一致を見つけようとしている場合は、に変更LookAt:=xlPartします。LookAt:=xlWhole

詳細は.Find こちら

于 2013-01-31T08:45:33.640 に答える