combo box question
VBA Telemetry pings you when your VBA projects fail
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: combo box question

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Hi everyone,

    Quick question. I have a userform that has a combo box on it. I populate the combo box by using the:

    Private Sub Userform_Initialize()
    With Me.combobox1
    .additem "first"
    .additem "second"]
    end with
    end sub

    The question is regarding the value of the combo box selection. Is there a way to have the combo box display, as in my code example, "first", but then when i ask for me.combobox1.value have it return something else, such as "1" or something to that effect.

    My goal is to have a simple statement in the combobox which users will see, but their selection will lead to a value which i need and predefined.

    Please let me know if this isnt clear enough. thanks for any help!

  2. #2
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Robfo0

    Sounds like an ideal situation for the choose Function.


    Private Sub ComboBox2_Change()

    If ComboBox2.ListIndex > -1 Then
    MyRealVal = Choose(ComboBox2.ListIndex + 1, 1, 2, 3, 4)
    End If

    End Sub

    The above code parses a pre-set value to the
    Global variable "MyRealVal" so if the user selected the first item in the Combo list it would parse 1, if the chose the second item it would parse 2 etc.



  3. #3
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-18 22:33, robfo0 wrote:
    Hi everyone,

    Quick question. I have a userform that has a combo box on it. I populate the combo box by using the:

    Private Sub Userform_Initialize()
    With Me.combobox1
    .additem "first"
    .additem "second"]
    end with
    end sub

    The question is regarding the value of the combo box selection. Is there a way to have the combo box display, as in my code example, "first", but then when i ask for me.combobox1.value have it return something else, such as "1" or something to that effect.

    My goal is to have a simple statement in the combobox which users will see, but their selection will lead to a value which i need and predefined.

    Please let me know if this isnt clear enough. thanks for any help!
    Use a select case and just reference the
    new value here eg.

    Private Sub ComboBox1_Change()

    Select Case ComboBox1.ListIndex

    Case 0
    MyNewValue = whatever
    Case 1
    MyNewvalue = whatever
    End Select

    End Sub


    Ivan


  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks very much, they both work great!

  5. #5
    Board Regular
    Join Date
    Feb 2002
    Location
    Ahmedabad Gujarat
    Posts
    303
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    I think same goal can be achieved by setting

    Boundcolumn, ColumnCount and Column Width Property


    see my example file comboboxproperty from my download section

    http://www.pexcel.com/download.htm

    file nos is 23


    ni****h desai

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com