I have an excel where I have populated few data in column 'A', I want the data to appear in the List box which is in my User Form. But I'm repeatedly getting the Run-time Error 380 stating "Could not set the RowSource Property. Invalid property value" Below is the code.
Private Sub ComboBox1_Change()
Dim wb123 As Workbook, TempFile As Workbook
Dim Tempsheet As Worksheet
Dim Last_Row As Integer
Set wb123 = ThisWorkbook
Set TempFile = Workbooks.Open("C:\Users\inkapb\AppData\Local\Temp\EPC AutoTool\Projects\" & Me.ComboBox1.Text & "\Template.xlsm")
Set Tempsheet = TempFile.Worksheets("Sheet2")
Last_Row = Tempsheet.Cells(Tempsheet.Rows.count, "A").End(xlUp).Row
With ListBox1
.ColumnCount = 1
.ColumnWidths = "50"
.RowSource = Tempsheet.Range("A2:A" & Last_Row).Address
End With
End Sub
And here is my excel sheet which contains the data.
The code works for me, when you are in the Userform Module, step through the code by pressing F8, this will step through each line of the code. See if these variables are collecting values.
If there are no values when you step through the lines, then something could be wrong with the "TempFile", such as the wrong sheet or something.
Also make sure your Rowsource is blank in the Listbox properties.
You can also use the List Properties instead of rowsource, for example:
Private Sub ComboBox1_Change()
Dim wb123 As Workbook, TempFile As Workbook
Dim Tempsheet As Worksheet
Dim Last_Row As Long, rng As Range
Set wb123 = ThisWorkbook
Set TempFile = Workbooks.Open("C:\Users\Dave\Downloads\" & ComboBox1)
Set Tempsheet = TempFile.Worksheets("Sheet2")
With Tempsheet
Last_Row = .Cells(.Rows.Count, "A").End(xlUp).Row
Set rng = .Range("A2:A" & Last_Row)
End With
With ListBox1
.ColumnCount = 1
.ColumnWidths = "50"
.List = rng.Value
End With
TempFile.Close True
End Sub