redspanna
Well-known Member
- Joined
- Jul 27, 2005
- Messages
- 1,602
- Office Version
- 365
- Platform
- Windows
Hi all,
I'm getting myself confused and can't seem to get this code to work in correct order....
What I would like it to happen is following....
The user is asked to input a string of data to be searched for into Textbox1 of the userform
This value is then searched for using a filter from the data stored in the "Database" sheet.
IF found then userform2 should be hidden and userform4 displayed on the "front" sheet..
IF NOT found then hide userform2 and display userform3
Hope this makes senses and thanks in advance
I'm getting myself confused and can't seem to get this code to work in correct order....
VBA Code:
Private Sub CommandButton1_Click()
Dim filterRange As Range
TextBox1.SetFocus
Application.ScreenUpdating = False
Sheets("Database").Select
With Range("B4:H" & Cells(Rows.Count, "B").End(xlUp).Row)
.AutoFilter
If Len(Me.TextBox1.Value) > 0 Then
.AutoFilter Field:=1, Criteria1:=Me.TextBox1.Value
On Error Resume Next
Set filterRange = .Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If filterRange Is Nothing Then
UserForm2.Hide
UserForm3.Show
Set filterRange = Nothing
End If
End If
Me.TextBox1.Value = ""
UserForm2.Hide
Sheets("Front").Select
UserForm4.Show
End With
Application.ScreenUpdating = True
End Sub
What I would like it to happen is following....
The user is asked to input a string of data to be searched for into Textbox1 of the userform
This value is then searched for using a filter from the data stored in the "Database" sheet.
IF found then userform2 should be hidden and userform4 displayed on the "front" sheet..
IF NOT found then hide userform2 and display userform3
Hope this makes senses and thanks in advance