using a worksheet range to populate a combo box in excel
Hi Kev,
the runtime error is because I supposed, that there is at least one
non-blank cell below A23. Now I added check for it. I hope I understood
correctly locations for all the data.
Private Sub cmdAdd_Click()
Dim rng1 As Range
Dim rng2 As Range
Dim i As Long
'ActiveWorkbook.Sheets("Financial copy").Activate
Set rng1 = Sheets("Financial copy").Range("A23").End(xlDown)
If rng1.Row = Application.Rows.Count Then
Set rng1 = Sheets("Financial copy").Range("A23")
End If
Set rng2 = Worksheets("customer copy").Range("a1").End(xlDown)
If rng2.Row = Application.Rows.Count Then
Set rng2 = Worksheets("customer copy").Range("a1")
End If
With rng1
For i = 0 To cboPartsused.ColumnCount - 1
..Offset(1, i).Value = cboPartsused.List(cboPartsused.ListIndex, i)
Next i
..Offset(1, i).Value = txtQuantity.Value
rng2.Offset(1, 0).Resize(1, 2).Value = .Offset(1, 0).Resize(1, 2).Value
'added this row to copy result from ComboBox
rng2.Offset(1, 2).Value = txtQuantity.Value
End With
txtQuantity.Value = 1 'consider using number 1 instead of string
"1"
cboPartsused.listindex=-1
' Range("A1").Select
End Sub
Now I suppose that you will change your combobox to contain 4 columns
of data from Temp Parts (Part description, Part number, Trade price and
list price). If will get lost in achieving this, please post the code
that you use for initializing the combobox.
Regards,
Ivan
|