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
 

Forum statistics

Threads
1,081,526
Messages
5,359,279
Members
400,523
Latest member
ExcelNewbie98

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top