Populating worksheet from userform combobox

B

buckchow

I'm having problems trying to get the selected item in the combobox t
populate the existing row in the worksheet. When I click on th
selected item in the combobox and save to the worksheet it adds th
item to the next empty row instead of using the existing row, creatin
a duplicate item entry. What I would like to happen is if the ite
already exists in the combobox, then add rest of the userform data t
that existing row on the worksheet. If a new item is entered in th
combobox, then the userform data would be entered in the next availabl
empty row
 
M

Martin Fishlock

Hi Buckchow,

Please can you post your code so that somebody could provide could help me.
 
B

buckchow

Listed below is the code I'm having a problem with:


Private Sub UserForm_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")
txtBatch1.SetFocus
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for a part number
If Trim(Me.txtBatch1.Value) = "" Then
Me.txtBatch1.SetFocus
MsgBox "Please enter a batch number"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtBatch1.Value
ws.Cells(iRow, 2).Value = Me.txtDate1.Value
ws.Cells(iRow, 3).Value = Me.txtCust1.Value
ws.Cells(iRow, 4).Value = Me.txtBoard1.Value
ws.Cells(iRow, 5).Value = Me.txtSerial1.Value
ws.Cells(iRow, 6).Value = Me.txtQty1.Value
ws.Cells(iRow, 18).Value = Me.txtStatus1.Value
ws.Cells(iRow, 17).Value = Me.txtNotes.Value

'clear the data
Me.txtBatch1.Value = ""
Me.txtDate1.Value = ""
Me.txtCust1.Value = ""
Me.txtBoard1.Value = ""
Me.txtSerial1.Value = ""
Me.txtQty1.Value = ""
Me.txtStatus1.Value = ""
Me.txtNotes.Value = ""
Me.txtBatch1.SetFocus

End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top