VBA Search for data in Textbox, and then add additional data from a userform in that row

Srobbery

New Member
Joined
Oct 22, 2014
Messages
2
Morning all,

I'm looking for help getting an idea from my head into a VBA code, I am very new to this!!

I have a spreadsheet that I have a column (column E) that is populated with a unique number by a barcode reader.

I am trying to get a command button to open a UserForm where the unique number is added into Textbox5 and then additional details would be entered into other Text and Combo boxes in the form.

In a perfect world when I hit the 'OK' button at the bottom of the form the code would search for the unique number in Textbox5 and then enter the other text into the other columns in that row.

Is this possible?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hello,

in a standard module use this code (this will be linked to the Command Button

Code:
Sub ADD_DATA_FROM_FORM()
        UserForm1.TextBox5.Value = Range("E2").Value
        UserForm1.Show
End Sub

add a Userform, with text boxes and a command button, names OK and enter this code for the userform

Code:
Private Sub OK_Click()
    Sheets("Sheet1").Range("F2").Value = TextBox2.Value
    Sheets("Sheet1").Range("G2").Value = TextBox3.Value
End Sub

you will need to change as required, but this should give you a start.
 
Upvote 0
Thanks for the response.

That has given me a start, but what I'm looking at is to enter a unique number in TextBox 1 of the UserForm, and then it to search for that value in Column E.

Once it finds that value, then it needs to enter the rest of the information in TextBox 2-10 into that row. It needs to be dynamic in where it puts the information, dependant on finding the unique numbers row number.

Sorry for not being clearer on locating the unique number for the row value to input the rest of the information into.

Thanks.
 
Upvote 0
Hello,

not sure what you want to do with the userform but as before:

in a standard module use this code (this will be linked to the Command Button

Code:
Sub ADD_DATA_FROM_FORM()
        UserForm1.Show
End Sub

add a Userform, with text boxes and a command button, names OK and enter this code for the userform

Code:
Private Sub OK_Click()
    MY_CODE = TextBox5.Value
    With Sheets("Sheet6")
        For MY_ROWS = 1 To .UsedRange.Rows.Count
            If Int(Range("E" & MY_ROWS).Value) = Int(MY_CODE) Or Range("E" & MY_ROWS).Value = MY_CODE Then
                TextBox2.Value = .Range("F" & MY_ROWS).Value
                TextBox3.Value = .Range("G" & MY_ROWS).Value
                Exit Sub
            End If
        Next MY_ROWS
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,221
Messages
6,129,585
Members
449,520
Latest member
TBFrieds

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top