RowSource Runtime Error 308

gemcgraw

Board Regular
Joined
Mar 11, 2011
Messages
72
I'm not sure if my issue is using Microsoft Office Excel Professional 2019 or something else. However, I have a combobox (ComboBoxVendors) on a userform that I need populated with vendor names. I'm trying to set the RowSource value in VBA code and getting, "Runtime error 308. Could not set the RowSource property. Invalid Row property value." Below is the code I have set on the Private Userform_Activate subroutine:
Code:
Dim Source As String
    'Find the last populated row in the range.    
        NextRow = Sheets("Vendors").Range("B" & Rows.Count).End(xlUp).Row


    'Assign the complex RowSource string into one stringed value
        Source = "Vendor!B2:B" & NextRow
   
    'Set the RowSource property.
        UserForm1.ComboBoxVendors.RowSource = Source



I'm using this sub to load the values in the ComboboxVendors on the UserForm ahead of time. There have been numerous suggestion on MrExcel and other forums that suggest several variations of this; however, I still get the same error. The only way around the error is to use this code:


UserForm1.ComboBoxVendors.RowSource = "Vendors!B2:B5"


This resolves the error and the ComboBoxVendors values load as expected. However, the range "B2:B5" will grow. Thus, I don't want to "hard-code" the range. And, I don't want to simply push the end of the range out to some crazy number and end up with a mile long of blanks.


What am I missing?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You should debug when the error occurs and determine what is the value of NextRow at that point. You can do this by hovering over the variable name. If you don't have any data yet, then it will start out as 1 if you have headers, and then you will be trying to set RowSource to Vendor!B2:B1 which is an invalid range. That is my best guess as to what is happening.
 
Last edited:
Upvote 0
This is untested:


Code:
Private Sub UserForm_Initialize()
    
UserForm1.ComboBoxVendors.List = Sheets("Vendors").Range("B2", Cells(Rows.Count, "B").End(xlUp)).Value

End Sub
 
Upvote 0
You should debug when the error occurs and determine what is the value of NextRow at that point. You can do this by hovering over the variable name. If you don't have any data yet, then it will start out as 1 if you have headers, and then you will be trying to set RowSource to Vendor!B2:B1 which is an invalid range. That is my best guess as to what is happening.

I have debugged NextRow and all over my other variables. Their values are correct. When I pack them in a string, they fail.
 
Upvote 0
This is untested:


Code:
Private Sub UserForm_Initialize()
    
UserForm1.ComboBoxVendors.List = Sheets("Vendors").Range("B2", Cells(Rows.Count, "B").End(xlUp)).Value

End Sub

That's throwing a RT 1004 "Application-Defined or Object-Defined error"
 
Upvote 0
That's throwing a RT 1004 "Application-Defined or Object-Defined error"
Oops.., forgot somethng:

Code:
Private Sub UserForm_Initialize()
With Sheets("Vendors")
UserForm1.ComboBoxVendors.List = .Range("B2", .Cells(Rows.count, "B").End(xlUp)).Value
End With
End Sub
 
Upvote 0
Oops.., forgot somethng:

Code:
Private Sub UserForm_Initialize()
With Sheets("Vendors")
UserForm1.ComboBoxVendors.List = .Range("B2", .Cells(Rows.count, "B").End(xlUp)).Value
End With
End Sub

Buddy that worked!! You get a big gold star! I have NEVER had that kind of trouble loading a range of values into a list or combobox before. I have been working on this for two months. I'll try to compare yours and see what exactly I was doing wrong. Thanks a million!
 
Upvote 0
Buddy that worked!! You get a big gold star! I have NEVER had that kind of trouble loading a range of values into a list or combobox before. I have been working on this for two months. I'll try to compare yours and see what exactly I was doing wrong. Thanks a million!
You're welcome & thanks for replying
 
Upvote 0
I didn't pick up the first time. Your problem is a missing qualification of Rows.

Code:
Dim Source As String
    'Find the last populated row in the range.    
        NextRow = Sheets("Vendors").Range("B" & [COLOR=#ff0000]Sheets("Vendors").[/COLOR]Rows.Count).End(xlUp).Row

When you reference Rows, you must qualify it with the appropriate worksheet, or it will default to the active worksheet. This is a very common error inside a qualified Range expression.

Akuini fixed that in his solution, although you could also fix it in your original code.
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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