Hi there
my problem in this search userform is, when i write a name in TextBox7 to search it in the sheet2
and the sheet 1 is active, then the code takes me to Err...? how to solve this problem ?
The other problem is, when sheet 2 is active the search code works fine until excution reaches
then the code jumps to excute
which show the Msgbox Wrong Entry, and realy it should not be shown in heer, why is that happen
Here are the full tow codes:
Code
Private Sub CommandButton1_Click()
Dim r As Long
Dim lRow, LastRow As Long
On Error GOTO Err
r = Sheet2.Cells.Find(What:=TextBox7.Value, After:=ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Row
Sheet2.Cells(r, 1).EntireRow.Offset(-1, 0).Select
'*Hide Rows From The selected up to the First Used:
lRow = Selection.Row
If lRow <= 5 Then Exit Sub
Sheet2.Rows("5:" & lRow).EntireRow.Hidden = True
Search.TextBox7.Value = ""
Unload Me
Exit Sub
Err:
MsgBox "There is a Mistake", vbCritical + vbMsgBoxRight, "Mistake Msg"
End Sub
Private Sub TextBox7_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57
' do not allow entry of numbers 0 to 9
KeyAscii = vbNull
MsgBox "Name Only", vbCritical + vbOKOnly + vbMsgBoxRight, "Wrong Entry "
TextBox7.Value = ""
End Select
End Sub
Display More