Russmeister57
New Member
- Joined
- Jun 5, 2015
- Messages
- 13
- Office Version
- 2010
- Platform
- Windows
Hi all,
I have trolled through all of the threads and cannot find the answer, if there is one to fix my code.
I have a sheet "TM Ownership", and on this sheet is a database of colleague details.
I have built a Userform to search for a name within this sheet and return all the data i need.
What i have currently is, if textbox1 is blank - tell me via msgbox else supply me with the data i have requested.
Currently, if i enter a name that isnt in the database, it still tries to look in the database and returns a runtime error 1004.
I cant for the life of me work out how to make it look first for the name, if it isnt in the database, then tell me via msgbox, but if it is, then return the data i have requested, but with keeping in the 'if textbox1.value is "" then' arguement.
I hope this makes sense, and any help is appreciated.
This is the code i have:
I have trolled through all of the threads and cannot find the answer, if there is one to fix my code.
I have a sheet "TM Ownership", and on this sheet is a database of colleague details.
I have built a Userform to search for a name within this sheet and return all the data i need.
What i have currently is, if textbox1 is blank - tell me via msgbox else supply me with the data i have requested.
Currently, if i enter a name that isnt in the database, it still tries to look in the database and returns a runtime error 1004.
I cant for the life of me work out how to make it look first for the name, if it isnt in the database, then tell me via msgbox, but if it is, then return the data i have requested, but with keeping in the 'if textbox1.value is "" then' arguement.
I hope this makes sense, and any help is appreciated.
This is the code i have:
VBA Code:
Private Sub Search_CDetails_Click()
'Search for Colleague Details
Dim TargetRow As Integer
Dim test1 As Range
Dim c As Range
Set test1 = Sheet6.Range("TM_Ownership_Start")
For Each c In test1
Next c
If TextBox1.Value = "" Then
MsgBox " No Data Has Been Selected!"
Else
TargetRow = Application.WorksheetFunction.Match(TextBox1, Sheets("TM Ownership").Range("Full_Name"), 0)
Sheets("data").Range("G5").Value = TargetRow
Colleague_Details.TextBox2 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 1).Value
Colleague_Details.TextBox4 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 2).Value
Colleague_Details.ComboBox3 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 3).Value
Colleague_Details.ComboBox1 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 4).Value
Colleague_Details.ComboBox4 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 5).Value
Colleague_Details.TextBox3 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 6).Value
Colleague_Details.TextBox5 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 8).Value
Colleague_Details.TextBox6 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 9).Value
Colleague_Details.TextBox7 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 10).Value
Colleague_Details.TextBox8 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 11).Value
Colleague_Details.TextBox9 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 12).Value
Colleague_Details.TextBox10 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 13).Value
Colleague_Details.CheckBox1 = Sheet6.Range("TM_Ownership_Start").Offset(TargetRow, 34).Value
End If
Exit Sub
End Sub
Last edited by a moderator: