Help with Code for MultiSource Data within a ComboBox

brianv

Board Regular
Joined
Dec 11, 2003
Messages
120
I am working a creating a userform that allows one to chose a specific part from a selection of parts to be inserted onto a specific sheet.

I found code from the Contextures Web site (Great Source for Information) that I have modified for this use. The contextures code will show 2 columns within the comboBox on the UserForm and then inserts it into its respective cells at its destination. None of this is a issue.

However, while I am OK in displaying the 2 columns ("C" for Part# and "D" for PartDescription) within the ComboBox I need to modify the code to insert the information offseted in Column "E&F" from the source list as well.

Column C = Part #
Column D = PartDescription
Column E = ID Code
Column F = Cost
Column G = Line#

I have modified the named range to include these Columns:
PartsIDList =OFFSET(CalcLists!$C$2,0,0,COUNTA(CalcLists!$C:$C)-1,1)
PartsLookup =OFFSET(PartIDList,0,0,,5)

And finally, when the information is displayed in the ComboBox, the 'feild' or the 'area' which is reserved for the width for the part number is to small and cuts off the part #'s, is there a way to increase this width.

Here is my code:
Private Sub cmdAdd_Click()
Dim lRow As Long
Dim lPart As Long
Dim ws As Worksheet
Set ws = Worksheets("Batt Calc")

'find first empty row in database
'Range("B65535").End(xlUp).Offset(1, 0).Select - (1st Attempt at finding the last row)
lRow = ws.Cells(Rows.Count, 2) _
.End(xlUp).Offset(1, 0).Row

lPart = Me.ComboPart.ListIndex

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

'copy the data to the database
With ws
.Cells(lRow, 3).Value = Me.ComboPart.Value
.Cells(lRow, 4).Value = Me.ComboPart.List(lPart, 1)
.Cells(lRow, 2).Value = Me.TextQty.Value
End With

'clear the data
Me.ComboPart.Value = ""
Me.TextQty.Value = 1
Me.ComboPart.SetFocus

End Sub
_________________________________________________________
Private Sub cmdClose_Click()
Unload Me
End Sub

_________________________________________________________
Private Sub UserForm_Initialize()
Dim cPart As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("CalcLists")

For Each cPart In ws.Range("PartIDList")
With Me.ComboPart
.AddItem cPart.Value
.List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value
End With
Next cPart
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi Brian

ColumnWidth is the property to set the width of each column.

Add one line that is :

Me.ComboPart.ColumnWidth = "100:100:100:100" '<- change as you wish
 
Upvote 0

Forum statistics

Threads
1,215,759
Messages
6,126,728
Members
449,332
Latest member
nokoloina

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