Select Columns in Worksheet based upon listbox selection

jmbhoy

New Member
Joined
May 9, 2009
Messages
6
Hi,

Looking for some VBA help, this is probably very simple (hopefully :)).

I have a form that allows user to select a worksheet from the current workbook using a combobox, the listbox will then display the contents of the selected worksheets header row (where row 1 is always the header). The listbox uses the following settings

Code:
           .ListStyle = fmListStyleOption
           .MultiSelect = fmMultiSelectMulti

Then within the listbox the user selects a number of columns from the chosen worksheet. I would like the columns selected in the listbox to also be selected in the worksheet. Ultimately I will be concatenating the data in the selected columns and looping through the worksheet looking for duplicates.

Here is the code I use to select the slected list box items, I need help in selecting the worksheet columns as a multi column range.

Code:
Private Sub btGetFields_Click()
Dim iCtr As Long
Dim strSearch As String
 
strSearch = ""
 
With Me.lbxColumns
For iCtr = 1 To .ListCount - 1
 
If .Selected(iCtr) Then
 
[COLOR=red]' CODE REQUIRED HERE TO SELECT COLUMNS WHERE[B] .List(iCtr) = COLUMN HEADER[/B][/COLOR]
[COLOR=red]' EACH TIME THE PROCEDURE LOOPS AN ADDITIONAL COLUMN WILL BE SELECTED[/COLOR]
 
End If

Next iCtr
 
End With
End Sub

Any help would be greatly appreciated.

Many thanks

James
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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