Could not set the RowSource property when I open another workbook

lattechic

New Member
Joined
Jun 24, 2018
Messages
14
Hi Experts,

I have a macro enabled workbook and when I start the program I get "Run-time error 380 - could not set the rowsource property. Invalid property value" in my UserForm initialize. Line in error is when I set the rowsource below.

Code:
Private Sub UserForm_Initialize()

    WorkbookName = ThisWorkbook.Name
    Set wb = Workbooks(WorkbookName)
     Set ws = wb.Worksheets("DOASaveAddtlCharges")

    LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    'set rowsource
    If LastRow = 1 Then
        ListBoxAddtlFees.RowSource = "DOASaveAddtlCharges!A2:C2"
    Else
        ListBoxAddtlFees.RowSource = "DOASaveAddtlCharges!A2:C" & LastRow
    End If

End sub

I am new to VBA. Please help.

Thanks in advance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,
see if this update to your code does what you want

Code:
Private Sub UserForm_Initialize()
    Dim ws As Worksheet
    Dim arr As Variant
   Dim lastrow As Long
    
    Set ws = ThisWorkbook.Worksheets("DOASaveAddtlCharges")
    lastrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
      
    arr = ws.Cells(2, 1).Resize(lastrow, 3).Value
    If Not IsArray(arr) Then arr = Array(arr)
    
    With Me.ListBoxAddtlFees
        .ColumnCount = 3
        .List = arr
    End With


End Sub

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top