il codice della from è
Dim myPrimo As Range, myCorr As Range, myK1 As Long 'questo codice cerca nel foglio archivio e usciti sia nelle celle che nei commenti
Private Sub CommandButton1_Click()
Dim i As Long
RAvvia:
userform1.Caption = "CERCA in cella"
TextBox1.SetFocus
TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
With ActiveSheet.Range("X2:AB65536, A2:d65536, e1:j65536")
If CheckBox2.Value = True Then lAt = 1 Else lAt = 2
If myPrimo Is Nothing Then
myK1 = 0
Set cfound = .Find(TextBox1.Text, LookIn:=xlValues, lookat:=lAt)
Else: Set cfound = .FindNext(myCorr)
End If
If cfound Is Nothing Then GoTo CkCmt
If Not myPrimo Is Nothing Then If cfound.Address = myPrimo.Address Then GoTo CkCmt
cfound.Select
If myPrimo Is Nothing Then Set myPrimo = cfound
Set myCorr = cfound: userform1.Caption = "TROVATO in cella"
End With
Exit Sub
CkCmt:
userform1.Caption = "CERCA in commento"
If myPrimo Is Nothing Then Set myPrimo = ActiveCell
If myCorr Is Nothing Then Set myCorr = ActiveCell
For i = myK1 + 1 To ActiveSheet.Comments.Count
Set Kmt = ActiveSheet.Comments(i)
If Not Application.Intersect(Kmt.Parent, Range("X2:AB65536, A2:B65536, e1:j65536")) Is Nothing Then
myFlag = 0
If CheckBox2.Value = True And UCase(Kmt.Text) = UCase(TextBox1.Text) Then myFlag = True
If CheckBox2.Value = False And Len(UCase(Kmt.Text)) > Len(Replace(UCase(Kmt.Text), UCase(TextBox1.Text), "")) Then myFlag = True
If myFlag = True Then
myK1 = i: Kmt.Parent.Select
userform1.Caption = "TROVATO in commento": Exit Sub
End If
End If
Next
FineKmt:
userform1.Caption = "------> FINE RICERCA"
Set myPrimo = Nothing
End Sub
Private Sub UserForm_initialize() 'questo codice fa si che se premo enter è come se schiacciassi il tasto trova della user from
CommandButton1.Caption = "trova": CommandButton1.Accelerator = "T": CommandButton1.Default = True
userform1.Caption = "cerca"
End Sub
Private Sub CommandButton2_Click() 'questo codice è collegato al tasto presenti della form e permette di cercare i nomi nel foglio archivio
Sheets("Archivio").Select
TextBox1.SetFocus 'permette di poter scrivere direttamente il nome da cercare senza fare click nella finestra
Set myPrimo = Nothing
End Sub
Private Sub CommandButton3_Click() 'questo codice è collegato al tasto usciti della form e permette di cercare i nomi nel foglio usciti
Sheets("usciti").Select
TextBox1.SetFocus
Set myPrimo = Nothing
End Sub
Private Sub CommandButton4_Click() 'questo codice è collegato al tasto colleghi della form e permette di cercare i nomi nel foglio colleghi
Sheets("colleghi").Select
TextBox1.SetFocus
Set myPrimo = Nothing
End Sub
Private Sub CommandButton5_Click() 'questo codice è collegato al tasto colleghi della form e permette di cercare i nomi nel foglio data nascita
Sheets("data nascita").Select
TextBox1.SetFocus
Set myPrimo = Nothing
End Sub
Private Sub CommandButton6_Click() 'collegato al tasto torna indietro per eliminare l'ultima operazione di ricerca nomi
With ActiveSheet.Range("b2:AB65536, A2:d65536")
Set cfound = .FindPrevious(cfound)
cfound.Select
End With
End Sub
Private Sub CheckBox2_Click() 'questo è collegato alla casella di controllo 'parola intera' della userfrom
Set myPrimo = Nothing
TextBox1.SetFocus
End Sub
Private Sub TextBox1_Change()
Set myPrimo = Nothing
End Sub
Private Sub UserForm_Activate()
TextBox1.SetFocus
End Sub
excel 2003