Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Combobox list source

Does anybody know if it is possible to achieve this?

I want the list source to a combobox to be two text strings (Solo &
Main) followed by the text entries in a column of cells (A2 downwards)
so that I end up with a combobox list that looks like this

Solo
Main
A1023452
A1238748
B126534
B128765
etc

where the A1023452 values are the values from cells A2 downwards.

Chris Thompson.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Combobox list source

Something like this:

Option Explicit
Private Sub UserForm_Initialize()

Dim myCell As Range
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ComboBox1
.AddItem "Solo"
.AddItem "Main"
For Each myCell In myRng.Cells
.AddItem myCell.Value
Next myCell
End With

End Sub

Chris Thompson wrote:

Does anybody know if it is possible to achieve this?

I want the list source to a combobox to be two text strings (Solo &
Main) followed by the text entries in a column of cells (A2 downwards)
so that I end up with a combobox list that looks like this

Solo
Main
A1023452
A1238748
B126534
B128765
etc

where the A1023452 values are the values from cells A2 downwards.

Chris Thompson.


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Combobox list source

Dave

Thanks for your help.
Where in the code view do I insert this portion of code as I have
tried it but it doesn't seem to be working (my mistake probably).

Chris.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Combobox list source

I added it to the initialization of the form. But you'll want to add to the
portion of your code that adds stuff to the listbox. (if you assign manually,
get rid of that and try the UserForm_Initialize procedure (code is behind the
userform.)

In fact, you could have the code just make sure you don't do it manually:
Option Explicit
Private Sub UserForm_Initialize()

Dim myCell As Range
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ComboBox1
.RowSource = ""
.AddItem "Solo"
.AddItem "Main"
For Each myCell In myRng.Cells
.AddItem myCell.Value
Next myCell
End With

End Sub

(I added one line (.rowsource = "") to the existing suggestion.)

Chris Thompson wrote:

Dave

Thanks for your help.
Where in the code view do I insert this portion of code as I have
tried it but it doesn't seem to be working (my mistake probably).

Chris.


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox dropdown list??????????? Tdp Excel Discussion (Misc queries) 3 November 25th 08 10:03 PM
ComboBox dropdown list? Tdp Excel Discussion (Misc queries) 0 October 14th 08 11:34 PM
.AddItem list and populating combobox with created list pallaver Excel Discussion (Misc queries) 8 June 27th 08 12:36 PM
how to give the source value for a combobox on excel spreadsheet Jithu Excel Discussion (Misc queries) 2 May 29th 07 12:50 PM
dependant combobox list L Sholes New Users to Excel 1 April 10th 06 11:29 AM


All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"