
Sub Filtra_Numero()
Dim Cerco As String
Dim Crit1 As String
With Sheets("Lavori Subappalto")
Cerco = InputBox("SCRIVI IL NOME DA CERCARE O PARTE DEL NOME")
If Cerco <> "" Then
.Unprotect
.Range("A6:E6").AutoFilter
Crit1 = "=*" & Cerco & "*"
.Range("A6:E6").AutoFilter Field:=1, Criteria1:=Crit1, Operator:=xlAnd
.Range("A6").Select
.Protect , DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True, userinterfaceonly:=True
End If
End With
End Sub |
.Range("A6:E6").AutoFilter Field:=1, Criteria1:=Cerco, Operator:=xlAnd |
Sub Filtra_Numero()
Dim Cerco As String, Cerco2 As String
Dim Crit1 As String
With Sheets("Lavoro")
Cerco = InputBox("SCRIVI IL 1° VALORE DA CERCARE")
Cerco2 = InputBox("SCRIVI IL 2° VALORE DA CERCARE")
If Cerco & Cerco2 <> "" Then
'If Cerco <> "" Then
.Unprotect
.Range("A6:E6").AutoFilter
'Crit1 = "=*" & Cerco & "*"
Crit1 = ">=" & Cerco & Cerco2
.Range("A6:E6").AutoFilter Field:=1, Criteria1:=Cerco, Operator:=xlAnd
.Range("A6").Select
.Protect , DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True, userinterfaceonly:=True
End If
End With
End Sub |
Sub Filtra_Numero()
Dim Cerco1 As String, Cerco2 As String 'Cerco1 e Cerco2 sono le variabile con le quali prendiamo il valore che scriveremo nelle 2 inputBox
Dim Crit1 As Variant, Crit2 As Variant 'Crit1 e Crit2 sono le variabili che servono per "legare" le variabili Cerco con uno o più operatori di confronto
'With Sheets("Foglio1")
With Sheets("Lavoro")
Cerco1 = InputBox("INSERISCI IL VALORE MINIMO PER LA RICERCA") 'lanciamo la InputBox per richiedere di scrivere il minimo valore da filtrare
Cerco2 = InputBox("INSERISCI IL VALORE MASSIMO PER LA RICERCA") 'lanciamo la InputBox per richiedere di scrivere il massimo valore da filtrare
If Cerco1 <> "" And Cerco2 <> "" Then
.Unprotect 'Rimuove protezione del foglio specificato
.Range("A6:E6").AutoFilter
Crit1 = ">=" & CInt(Cerco1) 'impostiamo una ricerca corrispondente a: tutti i valori compresi tra i valori della variabili Cerco1 e Cerco2
Crit2 = "<=" & CInt(Cerco2)
.Range("A6:E6").AutoFilter Field:=1, Criteria1:=Crit1, Operator:=xlAnd, Criteria2:=Crit2 'applichiamo il filtro sulla cella di inizio tabella (Field = 1), 'contenente il 'nome contenuto nell'intestazione del campo della Colonna 1 (la A)
.Range("A6").Select
.Protect , DrawingObjects:=False, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True, userinterfaceonly:=True
End If
End With
End Sub |
