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
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