Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Assigning values to a word in a drop down box

Is there a way to assign a different value to each option in a drop down box
so that when each selection is made in a form you can make a calculation?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Assigning values to a word in a drop down box


When I need something like this, I usually create a two-column dropdown and
set the width of the second column to 0 so it is not visible. Then, put the
items in the first column and their associated values in the second column.
You can then read the second column to get the value associate with the
selected item. In the following example, CommandButton1 loads a two-column
ComboBox with some sample data and CommandButton2 gets the selected item
and its associated value from the ComboBox.

Private Sub CommandButton1_Click()
''''''''''''''''''''''''''''''''''''''''
' Load up the array with some values.
''''''''''''''''''''''''''''''''''''''''
Dim Arr(1 To 3, 1 To 2)
Arr(1, 1) = "Item1"
Arr(1, 2) = "11"
Arr(2, 1) = "Item2"
Arr(2, 2) = "22"
Arr(3, 1) = "Item3"
Arr(3, 2) = "33"

With Me.ComboBox1
''''''''''''''''''''''''''''''''''''''''''''
' Set 2 columns and hide the second column.
''''''''''''''''''''''''''''''''''''''''''''
.ColumnCount = 2
.ColumnWidths = CStr(.Width * 0.85) & ";0"
'''''''''''''''''''''''''''''''
' Load the list with the array.
'''''''''''''''''''''''''''''''
.List = Arr
End With

End Sub

Private Sub CommandButton2_Click()
Dim ItemName As String
Dim ItemValue As Double

'''''''''''''''''''''''''''''''''''''''''''
' Get the seleted item from column 0
' and the associated value from column1.
'''''''''''''''''''''''''''''''''''''''''''
With Me.ComboBox1
If .ListIndex 0 Then
ItemName = .List(.ListIndex, 0)
ItemValue = CDbl(.List(.ListIndex, 1))
MsgBox "Item: " & ItemName & vbCrLf & _
"Value: " & CStr(ItemValue)
Else
MsgBox "No Item Selected"
End If
End With
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Aleyna0515" wrote in message
...
Is there a way to assign a different value to each option in a drop down
box
so that when each selection is made in a form you can make a calculation?


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
Assigning point values? Riptide Excel Worksheet Functions 2 July 23rd 07 12:54 PM
Assigning values to drop-down list options i*sam Excel Discussion (Misc queries) 3 May 22nd 07 04:43 PM
Help assigning a number to a word modicon2 Excel Discussion (Misc queries) 7 August 21st 06 03:37 AM
Assigning values to letters Cheri Excel Worksheet Functions 3 December 20th 05 03:55 AM
assigning values by intervals Pete at FMR Excel Worksheet Functions 2 August 8th 05 03:55 PM


All times are GMT +1. The time now is 08:59 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"