Please help, I have been scouring the internet for 2 days and cannot find the answer!
I want to populate a userform listbox that has 2 columns which is looking at a dynamic range on another workbook. I have managed to populate the first column, which is column A, but cannot make it look at column B as well.
The code I have is:
any help would be greatly appreciated!!
Thanks in advance
I want to populate a userform listbox that has 2 columns which is looking at a dynamic range on another workbook. I have managed to populate the first column, which is column A, but cannot make it look at column B as well.
The code I have is:
Code:
Private Sub UserForm_Initialize()Workbooks.Open "C:\Users\Carly\Desktop\Carly\MASTER.xlsx"
Worksheets("Companies").Activate
If Workbooks.Count <= 3 Then
Application.Visible = False
Else
Windows("MASTER.xlsx").Visible = False
End If
Dim compRange As Range
On Error GoTo ErrorHandle
Set compRange = Workbooks("MASTER.xlsx").Worksheets("Companies").Range("A2")
If Len(compRange.Formula) = 0 Then
MsgBox "The list is empty"
GoTo BeforeExit
End If
If Len(compRange.Offset(1, 0).Formula) > 0 Then
Set compRange = Range(compRange, compRange.End(xlDown))
End If
CompaniesListBox.RowSource = compRange.Address
BeforeExit:
Set compRange = Nothing
Exit Sub
ErrorHandle:
MsgBox Err.Description
Resume BeforeExit
End Sub
any help would be greatly appreciated!!
Thanks in advance