Hi all,
finaly i use this code. It Works only in active sheet where i have data/source but it Works.
I have only one short question to this:
How can i redefine/clear static varible in this code? I need it because after pressing „Clear“ button i want to start search from begining.
this is my textbox code
Private Sub TextBoxALL_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'Do
'Loop
Sheets("ALL").TextBoxALL.Activate
If Me.TextBoxALL.Value = "" Then Exit Sub
If KeyCode = 13 Then
Dim rSrch As Range
Static rCl As Range
Dim fnd As String
Dim meno As String
Dim FirstAddress As String
meno = Range("j1").Value
fnd = Me.TextBoxALL.Value
Set rSrch = Range(Cells(20, 1), Cells(Rows.Count, 2).End(xlUp))
If rCl Is Nothing Then
Set rCl = rSrch.Cells(1, 1)
Else
Set rCl = rCl.Offset(1, 0)
If Application.Intersect(rCl, rSrch) Is Nothing Then Set rCl = rSrch.Cells(1, 1)
End If
With rSrch
Set rCl = .Find(fnd, After:=rCl, LookIn:=xlValues)
If Not rCl Is Nothing Then
FirstAddress = rCl.Address
Cells(Rows.Count, 35).End(xlUp).Offset(0, -25).Value = rCl.Value
If rCl.Value = meno Then
Set rCl = .FindNext(rCl)
Cells(Rows.Count, 35).End(xlUp).Offset(0, -25).Value = rCl.Value
End If
Else
MsgBox "Dlžník sa nenachádza v našom archíve (rok 2007 - súčasnosť) "
Set rCl = Nothing
End If
End With
With TextBoxALL
.SelStart = 0
.SelLength = 500 ''anything >= to len of text
End With
End If
End Sub
this is my clear button code
Private Sub ZMAZvALL_Click()
TextBoxALL.Value = ""
Range("j1").ClearContents
ActiveSheet.TextBoxALL.Activate
Me.TextBoxALL = vbNullString
'ActiveSheet.Protect
End Sub
i tried it to add this in clear code but it doesnt works
Static rCl As Range
With rCl
rCl = Nothing
End With
thank you very much