This has perplexed me for the past year. I have a search userform with a textbox designated for searching a worksheet "combined" for a specific value. This search userform is called from the primary worksheet "sheet2" via another userform.
Once the value is found, the other textboxes in the search userform populate with data adjacent to the found value. This executes with no issue.
I need to maintain focus on "sheet2" but worksheet "combined" takes the focus.
Private Sub CmdSearch_Click()
Set ws = Worksheets("Combined")
Dim Nullstring
Application.ScreenUpdating = False
If mytext.Value = "" Or Nullstring Then
MsgBox "Please enter a ticket number"
mytext.SetFocus
Exit Sub
End If
Dim strFind
Dim rSearch As Range 'range to search
Set rSearch = ws.Range("D:D")
Dim c
strFind = mytext.Value
If strFind = Nullstring Then GoTo error1
With rSearch
Set c = .Find(strFind, LookIn:=xlValues, MatchCase:=True)
If Not c Is Nothing Then 'found it
MsgBox strFind & " FOUND", vbOKOnly
c.Select
With Me
.mytext.Value = ActiveCell.Value
.txtsdm.Value = ActiveCell.Offset(0, -3).Value
.txtsdd.Value = ActiveCell.Offset(0, -2).Value
.txtsdy.Value = ActiveCell.Offset(0, -1).Value
.mytext.Value = ActiveCell.Offset(0, 0).Value
.txtdpm.Value = ActiveCell.Offset(0, 1).Value
.txtdpd.Value = ActiveCell.Offset(0, 2).Value
.txtdpy.Value = ActiveCell.Offset(0, 3).Value
.txtnet.Value = ActiveCell.Offset(0, 4).Value
.txtmar.Value = ActiveCell.Offset(0, 5).Value
.txtgross.Value = ActiveCell.Offset(0, 6).Value
.txtpab.Value = ActiveCell.Offset(0, 7).Value
.txtadj.Value = ActiveCell.Offset(0, 8).Value
.txtdel.Value = ActiveCell.Offset(0, 9).Value
.txtint.Value = ActiveCell.Offset(0, 10).Value
.txtfin.Value = ActiveCell.Offset(0, 11).Value
End With
'cmdedit.Visible = True
'cmdupdate.Visible = True
'cmddelete.Visible = True
Else
MsgBox "NO EXACT MATCH WAS FOUND! PLEASE TRY AGAIN"
End If
End With
error1: mytext.Value = ""
End Sub