Get Adobe Flash player

“Trova” per selezionare una cella

Questo esempio cerchera’ nella colonna A del foglio “Foglio1″ il valore del campo input.
FindString = “parola da trovare”
o
FindString = Sheets(“Foglio1″).Range(“D1″).Value

Questo codice troverà il valore dell’inputbox nella prima cella:

Sub Find_First()
    Dim FindString As String
    Dim Rng As Range
    FindString = InputBox("Inserire il valore da cercare")
    If Trim(FindString) <> "" Then
        With Sheets("Foglio1").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
            If Not Rng Is Nothing Then
                Application.Goto Rng, True
            Else
                MsgBox "Non ho trovato nulla"
            End If
        End With
    End If
End Sub

Se avete più di una occorrenza del valore, questo codice troverà l’ultima:

Sub Find_Last()
    Dim FindString As String
    Dim Rng As Range
    FindString = InputBox("Inserire il valore da cercare")
    If Trim(FindString) <> "" Then
        With Sheets("Foglio1").Range("A:A")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(1), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False)
            If Not Rng Is Nothing Then
                Application.Goto Rng, True
            Else
                MsgBox "Non ho trovato nulla"
            End If
        End With
    End If
End Sub

Se avete date nella colonna A questo esempio troverà nelle celle la data di oggi:

Sub Find_Todays_Date()
    Dim FindString As Date
    Dim Rng As Range
    FindString = CLng(Date)
    With Sheets("Foglio1").Range("A:A")
        Set Rng = .Find(What:=FindString, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlFormulas, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
        If Not Rng Is Nothing Then
            Application.Goto Rng, True
        Else
            MsgBox "Non ho trovato nulla"
        End If
    End With
End Sub

Categorie

Contatore

442208 visitatori