Sorry, it was just I realized it would be easier to keep up to date the price list etc. Sorry for the inconvenience.
I pasted the code into the form:
Option Explicit
Private Sub lbxProducts_Click()
With Me.lbxProducts
ActiveCell.Value = .Value
ActiveCell.Offset(0, 1).Value = .List(.ListIndex, 1)
End With
End Sub
Private Sub UserForm_Initialize()
Dim oWbk As Workbook
Dim rdata As Range
Dim Col1Wid As Long
Dim Col2Wid As Long
Col1Wid = Range("Products").Columns(1).Width
Col2Wid = Range("Products").Columns(2).Width
On Error GoTo exit_handler
Application.ScreenUpdating = False
'check if workbook containing source is open if not open it.
If Not IsOpen("2.xlsx") Then
Set oWbk = Workbooks.Open("C:\Users\Taurus\Desktop\[2.xlsx")
Else: Set oWbk = Workbooks("C:\Users\Taurus\Desktop\[2.xlsx")
End If
'this is the data to load to combobox
With oWbk.Worksheets(1)
Set rdata = .Range(.Cells(1, 1).Cells(.Rows.Count, 2).End(xlUp))
End With
With Me.lbxProducts
.ColumnCount = 2
.ColumnWidths = Col1Wid & ";" & Col2Wid
.RowSource = rdata.Address(external:=True)
.ListIndex = 0
End With
exit_handler:
Set oWbk = Nothing
Set rdata = Nothing
Application.ScreenUpdating = True
On Error GoTo 0
End Sub
Function IsOpen(wbName As String) As Boolean
Dim Wb As Workbook
On Error Resume Next
Set Wb = Workbooks(wbName)
If Err = 0 Then IsOpen = True
End Function
It opens the form but nothing in it?
Also do I have to have the other file open? Because I did try this:
='C:\Users\Taurus\Desktop\[2.xlsx]Sheet1'!A3
and it updated without being opened.
Bookmarks