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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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