run time error 380 rowsource property invalid property value

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi good morning, Please can you help me, i get a 'Run time error 380 property invalid property value' and it highlights in yellow the line below, but i have no idea how to correct it as i cant see what the issue is
VBA Code:
.RowSource = "Data_Display!A2:K" & lr
anf this is the whole code for my listbox -
Code:
Sub Refresh_Listbox()

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Data")
 
Dim dsh As Worksheet
Set dsh = ThisWorkbook.Sheets("Data_Display")

''''''''''' Copy Data ''''''''''
dsh.Cells.Clear
sh.AutoFilterMode = False

If Me.cmb_Filter_By.Value <> "ALL" Then
    sh.UsedRange.AutoFilter Application.WorksheetFunction.Match(Me.cmb_Filter_By.Value, sh.Range("1:1"), 0), "*" & Me.txt_Search.Value & "*"
End If

sh.UsedRange.Copy dsh.Range("A1")

sh.AutoFilterMode = False

Dim lr As Long
lr = Application.WorksheetFunction.CountA(dsh.Range("A:A"))

If lr = 1 Then lr = 2

With Me.ListBox1
    .ColumnHeads = True
    .ColumnCount = 11
    .ColumnWidths = "20,160"
    .RowSource = "Data_Display!A2:K" & lr
End With

End Sub

Really hope you can help me please.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
What is the actual value of lr at the time the error occurs?
 
Upvote 0
lr is supposed to be a row number. What value does it actually have (0, 1, 2 etc) when the code errors?
 
Upvote 0
It looks like it happens when the date is entered which is row E
 
Upvote 0
That doesn't answer my question. What is the actual value of lr when the code errors?
 
Upvote 0
lr is a variable which contains a number value. What is its actual value when the code runs and causes an error? Is it 1, 2, 3, 482 or something else?

This line:

VBA Code:
.RowSource = "Data_Display!A2:K" & lr

is trying to assign a range to populate the listbox. It uses lr to determine the last row of that range so I am trying to determine if it is a valid number. If lr is 0, then the range would be A2:K0 which is not a valid range.
 
Upvote 0
I have attached a screenshot of the page it links into, does this help? sorry im not being very helpful.
 
Upvote 0
No, you haven't attached anything.

I just need to know what the value of the variable is. Add a line before the Rowsource line that is just:

Code:
Msgbox lr

and run the code again and tell me what the message says.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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