run time error 380 on user form

Mr Marvin

New Member
Joined
Sep 8, 2021
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
i have code below which all of sudden has started to come with this error

"run-time error 380: Could not set the RowSource property. Invalid property value."

when i debug it, it highlights LstCodeSearchResults.RowSource = "SearchResult" below. can some one please help identify this issue to fix it. thanks


Private Sub CmdCodesSearch_Click()

Dim RowNum As Long
Dim SearchRow As Long

RowNum = 2
SearchRow = 2

Worksheets("Refer Codes").Activate

Do Until Cells(RowNum, 1).Value = ""
If InStr(1, Cells(RowNum, 1).Value, CodesSearch.Value, vbTextCompare) Then
Worksheets("CodesSearch").Cells(SearchRow, 1).Value = Cells(RowNum, 1).Value
Worksheets("CodesSearch").Cells(SearchRow, 2).Value = Cells(RowNum, 2).Value
Worksheets("CodesSearch").Cells(SearchRow, 3).Value = Cells(RowNum, 3).Value
SearchRow = SearchRow + 1

End If
RowNum = RowNum + 1
Loop

If SearchRow = 2 Then
MsgBox "No Codes were found that match your search criteria"
Exit Sub
End If

LstCodeSearchResults.RowSource = "SearchResults"
 

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.
Hi Mr Marvin. SearchResults isn't set to anything? Also adding quotes around SearchResults makes it a string whereas rowsource needs a number. HTH. Dave
 
Upvote 0
Whoops my bad. Finished my coffee. Rowsource does need a cell address which would be a string. So if you coded...
Code:
Dim SearchResults as String
SearchResults = "Sheets("Sheet1").Range("A" & 1)"
LstCodeSearchResults.RowSource = SearchResults
Seems like it should work. Dave
 
Upvote 0
Whoops my bad. Finished my coffee. Rowsource does need a cell address which would be a string. So if you coded...
Code:
Dim SearchResults as String
SearchResults = "Sheets("Sheet1").Range("A" & 1)"
LstCodeSearchResults.RowSource = SearchResults
Seems like it should work. Dave
thank dave, but it i keep getting a syntax error with that
 
Upvote 0
Hi again Mr Marvin. I should have asked what the LstCodeSearchResults is? Anyways, I had the syntax wrong. For a Listbox1 on userform1 with A1 as rowsource....
Code:
Dim SearchResults As String
SearchResults = "Sheet1!A1"
UserForm1.ListBox1.RowSource = SearchResults
I googled and came across a similar syntax as the error line of code that U used for a combobox where the rowsource was a named range which would have been "SearchResults" in your example. Maybe you deleted the named range? Anyways, to VBA set the rowsource for a listbox or combobox the syntax seems to be...
Code:
Dim SearchResults As String
SearchResults = "Sheet1!A1:A5"
LstCodeSearchResults.RowSource = SearchResults
HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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