• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

SEARCH CODE EXCEL VBA

lamojmohan

New Member
Private Sub CommandButton5_Click()

binnew = False
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Trows = Worksheets("sheet2").Range("A1:A100").CurrentRegion.Rows.Count
For i = 2 To Trows
If Val(Trim(Worksheets("sheet2").Cells(i, 1).Value)) = Val(Trim(ComboBox1.Text)) Then

TextBox1.Text = Worksheets("sheet2").Cells(i, 1).Value
TextBox2.Text = Worksheets("sheet2").Cells(i, 2).Value
TextBox3.Text = Worksheets("sheet2").Cells(i, 3).Value
TextBox4.Text = Worksheets("sheet2").Cells(i, 4).Value

Exit For
End If
Next i
If TextBox1.Text = "" Then
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Else
CommandButton1.Enabled = True
CommandButton2.Enabled = True
CommandButton7.Enabled = True


End If



End Sub
 
Please read the rules as Marc says in order for us to understand the issue and what you are trying to achieve.
Based on your code, It appears that you are trying to return some data to the user if a match occurs between a combo box value and a list on 'sheet2'.

I would suggest that the solution would be to remove the val() functions on line 10, as they are not required to find this match and may in fact be causing incorrect matches, however I would also say that looping through every item in the list is not the best way to go about what it appears you are trying to do.

I cannot say for sure as you have provided no further details other than your code.

Please rectify this and follow the forum rules if you wish for a more comprehensive response.
 
Back
Top