Exclude columns when filling listbox

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
239
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I fill my listbox with the following columns from the sheet BMR data;

Tracker QA on the floor New.xlsm
ABCDE
12022
2MonthMaandInOut
3OctoberOctober 229693
4November157133
5December99113
BMR data


I use the following code for it;

VBA Code:
Option Explicit
Dim Ary As Variant

Private Sub UserForm_Initialize()
   Ary = Sheets("BMR data").Range("B3", Sheets("BMR data").Range("B" & Rows.Count).End(xlUp).Offset(, 7)).Value
   With Me.lstSearchResults
      .ColumnCount = 4
      .ColumnWidths = "150;70;48;48"
      .List = Ary
   End With
End sub

Now it showing all columns and data from B, C and D.

Is it possible to code it like i can tell wich columns to show?
I would like to show Column B, D and E and exclude column C.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I found some easier code;

VBA Code:
Private Sub UserForm_Initialize()
Dim lindex&
'Puts the user form in the middle of the Excel screen when opened.
Me.StartupPosition = 0
Me.Top = (Application.Height / 2) - (Me.Height / 2)
Me.Left = (Application.Width / 2) - (Me.Width / 2)
Me.lstSearchResults.ColumnCount = 4
Me.lstSearchResults.List = Sheets("BMRcloset").[F7:I37].Value
With Me.lstSearchResults
.List(lindex, 0) = (Format((.List(lindex, 0)), "dd/mmm/yy"))
End With
End Sub

Still same question:

The range is F7:I37, can I exclude a column from this? For example column H i want to exclude
 
Upvote 0
Now it showing all columns and data from B, C and D.

Is it possible to code it like i can tell wich columns to show?
I would like to show Column B, D and E and exclude column C.

I would suggest that you simply hide Column C by setting the ColumnWidths property for the column to 0 . . .

VBA Code:
.ColumnWidths = "150;0;48;48"

For addition information regarding the ColumnWidths property, have a look at the following article...


Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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