Hi there, I have a sheet with a text field and a command button to do a search according to the text in the text field. Also I have a reset button.
The issue is that when entering numbers or dates in the text field and execute a search, the macro goes to the end of the table without showing any lines found.
Can someone tell me what I do wrong?
Thanks for your help.
Marc
Here is the link to the file in the dropbox. https://www.dropbox.com/s/xch0liyu6m3h5k6/Test_Search.xlsm?dl=0
This is the macro to do the search:
Private SubCommandButton1_Click()
IfSheets("Tabelle1").FilterMode = True Then
Sheets("Tabelle1").ShowAllData
End If
Application.EnableEvents = False
Application.ScreenUpdating = False
'Set search in cells B2-J10 for full textsearch in the fields
Sheets("Tabelle1").Cells(2,2).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(3,3).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(4,4).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(5,5).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(6,6).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(7,7).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(8,8).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(9,9).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(10,10).Value = "*" & Suchfeld.Text & "*"
' filtering according to columns M-U as persearch criteria in cells B1-J10
Sheets("Tabelle1").Columns("M:U").AdvancedFilterAction:=xlFilterInPlace, CriteriaRange:=Range _
("B1:J9"), Unique:=False
Application.ScreenUpdating = True
Application.EnableEvents = True
Range("M2").Select 'pointer to M2"
End Sub
This is the macro to do the reset:
Sub reset()
'reset filter
Application.ScreenUpdating = False
Application.EnableEvents = False
If Sheets("Tabelle1").FilterMode = True Then
Sheets("Tabelle1").ShowAllData
End If
ActiveCell.Offset(1, 0).Select
Sheets("Tabelle1").Suchfeld.Text = "" 'clears text field
If Sheets("Tabelle1").FilterMode = True Then
Sheets("Tabelle1").ShowAllData
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
ActiveSheet.Range("O65536").End(xlUp).Offset(1,0).EntireRow.Select
Range("M" & (ActiveCell.Row)).Select
End Sub
The issue is that when entering numbers or dates in the text field and execute a search, the macro goes to the end of the table without showing any lines found.
Can someone tell me what I do wrong?
Thanks for your help.
Marc
Here is the link to the file in the dropbox. https://www.dropbox.com/s/xch0liyu6m3h5k6/Test_Search.xlsm?dl=0
This is the macro to do the search:
Private SubCommandButton1_Click()
IfSheets("Tabelle1").FilterMode = True Then
Sheets("Tabelle1").ShowAllData
End If
Application.EnableEvents = False
Application.ScreenUpdating = False
'Set search in cells B2-J10 for full textsearch in the fields
Sheets("Tabelle1").Cells(2,2).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(3,3).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(4,4).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(5,5).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(6,6).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(7,7).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(8,8).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(9,9).Value = "*" & Suchfeld.Text & "*"
Sheets("Tabelle1").Cells(10,10).Value = "*" & Suchfeld.Text & "*"
' filtering according to columns M-U as persearch criteria in cells B1-J10
Sheets("Tabelle1").Columns("M:U").AdvancedFilterAction:=xlFilterInPlace, CriteriaRange:=Range _
("B1:J9"), Unique:=False
Application.ScreenUpdating = True
Application.EnableEvents = True
Range("M2").Select 'pointer to M2"
End Sub
This is the macro to do the reset:
Sub reset()
'reset filter
Application.ScreenUpdating = False
Application.EnableEvents = False
If Sheets("Tabelle1").FilterMode = True Then
Sheets("Tabelle1").ShowAllData
End If
ActiveCell.Offset(1, 0).Select
Sheets("Tabelle1").Suchfeld.Text = "" 'clears text field
If Sheets("Tabelle1").FilterMode = True Then
Sheets("Tabelle1").ShowAllData
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
ActiveSheet.Range("O65536").End(xlUp).Offset(1,0).EntireRow.Select
Range("M" & (ActiveCell.Row)).Select
End Sub