Could not set the RowSource property. Invalid property value

borgtamer

New Member
Joined
Dec 3, 2015
Messages
2
I have a spreadsheet with the name "S1" in a workbook with the name "W1" and have an addin with the name "A1".
In A1 there is a listbox in a user form.

I want to bind a range in S1 to the listbox in A1. This is the only way I can display more than 10 columns of S1 in the list box.

When I run the macro I get "Run-time Error 380: Could not set the RowSource property. Invalid property value."

The macro below is in the addin A1 user form UserForm. I cannot see what I am doing wrong so any help is appreciated. Thank you in advance.

Joe

Code:
Private Sub UserForm_initialize()
    'Display a range of cells in S1 in ListBox1
    Dim lastRow As Integer
    Dim firstRow As Integer
    Dim lastCol As String
    Dim rowNum As Integer
    Dim colNum As Integer
    Dim rng As String
    Dim rs As String
    Dim prefix As String
    
    With Workbooks("W1.xlsm").Sheets("S1")
        lastRow = .Cells(.Rows.Count, firstRow).End(xlUp).row
        lastCol = "O" 'For testing
        firstRow = 5 'For testing
        Me.ListBox1.ColumnCount = 15 'For testing
        Me.ListBox1.ColumnHeads = True
        
        rng = ".Range(" & Chr(34) & "A" & firstRow & ":" & lastCol & lastRow & Chr(34) & ").Address()"
        prefix = "Workbooks(" & Chr(34) & "W1.xlsm" & Chr(34) & ").Sheets(" & Chr(34) & "S1" & Chr(34) & ")"
        rs = prefix & rng
        Me.ListBox1.RowSource = rs
      End With
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
i think your over complicating it
Code:
        lastCol = "O" 'For testing
        firstRow = 5 'For testing
        
        lastRow = .Cells(.Rows.Count, firstRow).End(xlUp).Row
        
        Me.ListBox1.ColumnCount = 15 'For testing
        Me.ListBox1.ColumnHeads = True
        
        rng = "A" & firstRow & ":" & lastCol & lastRow
        
        Me.ListBox1.RowSource = "S1!" & rng

also i think your last row needs to after first row otherwise how can you use first row before you set it?

ps
the syntax you have lastrow working
"firstrow" is actually asking what column it look under
 
Last edited:
Upvote 0
Also, you don't actually have to use Rowsource to get more than 10 columns, you just can't use AddItem:

Code:
Me.ListBox1.List = Sheets("S1").Range("A" & firstRow & ":" & lastCol & lastRow).Value
will work just fine (and is my preference, unless you really need column headers)
 
Upvote 0

Forum statistics

Threads
1,214,835
Messages
6,121,880
Members
449,057
Latest member
Moo4247

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