Altering .Value of combobox when using arrays

John_McClane

New Member
Joined
Apr 30, 2013
Messages
27
Good Afternoon,

I am using the following code from Locke-Garmin to automatically populate textboxs:

Code:
Option Explicit

Private People As Collection


Private Sub UserForm_Initialize()

Set People = New Collection

Call PopulatePeopleCollection

With ComboBox1
.List = People_Collection_To_List()
.ColumnCount = 2
.BoundColumn = 2
.ColumnWidths = "1;0"
End With

End Sub


Private Sub PopulatePeopleCollection()

AddPerson "Locke", "Locke@Locke.com"
AddPerson "Garmin", "Garmin@Garmin.com"


End Sub


Private Sub AddPerson(Name As String, Email As String)
People.Add Array(Name, Email)
End Sub


Private Function People_Collection_To_List() As Variant()

Dim ReturnArray As Variant
Dim x As Long


ReDim ReturnArray(1 To People.Count, 0 To 1)

For x = 1 To People.Count
ReturnArray(x, 0) = People(x)(0)
ReturnArray(x, 1) = People(x)(1)
Next x

People_Collection_To_List = ReturnArray

End Function


Private Sub ComboBox1_Change()
TextBox1.Value = ComboBox1.Value

End Sub

...which works perfectly. I am using the userform to send an email with the information now input from the code above and would like it to send the value of combobox1 as part of the body. However, when I use me.combobox1.value it is returning the value as the email address of the person and not the name - is there a way for it to return the name instead?

If it would be helpful I can post the code I am using to send the email.

Thank you in advance for your time and help,

John
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Maybe:
Rich (BB code):
Private Sub ComboBox1_Change()

    Dim selectedIndex As Long
    selectedIndex = ComboBox1.ListIndex
    
    If selectedIndex > -1 Then 'Nothing selected
        TextBox1.Value = ComboBox1.List(selectedIndex, 0)
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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