Data from Table to Listbox

arnabmit

New Member
Joined
Mar 28, 2009
Messages
27
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi,

I am trying to get the content of a formatted table into an ActiveX list box lstPrev. I am getting error 438 "Object doesn't support this property or method".

What am I doing wrong?

Note: ShtName is a public variable

VBA Code:
Dim dbSheet As Worksheet
Dim dbTable As ListObject

Set dbSheet = ThisWorkbook.Sheets("Form")
Set dbTable = ThisWorkbook.Sheets(ShtName).ListObjects(ShtName)

ActiveSheet.lstPrev.RowSource = dbTable.DataBodyRange.Address(External:=True)
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
ActiveX listboxes do not have a rowsource property, try
VBA Code:
ActiveSheet.lstPrev.List = dbTable.DataBodyRange.Value
 
Upvote 0
ActiveX listboxes do not have a rowsource property, try
VBA Code:
ActiveSheet.lstPrev.List = dbTable.DataBodyRange.Value
Thank you! Perils of being a noob.

I am guessing the following property is also not available? because I see the column header, but without any text

VBA Code:
ActiveSheet.lstPrev.ColumnHeads = True
 
Upvote 0
If you want the header use ListFillRange instead
VBA Code:
ActiveSheet.LstPrev.ListFillRange = dbTable.DataBodyRange.Address(, , , 1)
 
Upvote 0
Solution
If you want the header use ListFillRange instead
VBA Code:
ActiveSheet.LstPrev.ListFillRange = dbTable.DataBodyRange.Address(, , , 1)

Worked perfectly! Thank you so much!
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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