Reputation: 95
I need to assign a code to the combo box selection. So my combo box has Locations list. If United States is selected, US is then written in the database, If United Kingdom, then UK, if Philippines, then PH. I don't know how to put this into a vba code since i have to combine this with another combo box value like a string.
.Cells(iRow, 2).Value = cmbLoc.Value & "_" & cmbProg.Value
Wherein cmbLoc is the combo box i need help with.
Upvotes: 2
Views: 400
Reputation: 27269
Assuming your table is in Info
worksheet where Country is column A and Code in column B, update your code to this:
Dim sCode as String
sCode = Worksheets("Info").Columns(1).Find(cmbLoc.Value,lookat:=xlWhole).Offset(,1)
.Cells(iRow, 2).Value = sCode & "_" & cmbProg.Value
bear in mind that I did not do any error checking, so I assume country will always bear there. Also, you can use Application.WorksheetFunction.Vlookup
if you prefer.
Upvotes: 3