Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ComboBox and Excel Range question

7 views
Skip to first unread message

Todd

unread,
May 21, 2010, 12:34:13 PM5/21/10
to
I've searched Google-land and have found articles close to what I need, but
not quite. I know this has to be a common task so maybe someone can point
me in the right direction.

I have a Word doc with a userform. The userform has a ComboBox
(cmbPortfolio) and a text box (txtPortfolioDetails). I simply want
cmbPortfolio to get its list from column A in Excel. When a person makes a
choice, it inputs the result of the corresponding column B into
txtPortfolioDetails. I have a dynamic range named "rngPortfolio" assigned to
columns A and B in the spreadsheet. This sounds like it would be simple,
yet I can't seem to get started.

Thanks in advance!!!

Jay Freedman

unread,
May 21, 2010, 4:23:46 PM5/21/10
to

Take a look at the article
http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm, especially the code
samples labeled "Excel Example" 1 through 3 that show how to get the data
from Excel into the .List member of the combo box. Although Greg uses a list
box, the same technique works with a combo box (which is really just the
combination of a list box and an edit box).

Your combo box's list should display only the first column, but it can also
invisibly store the second column. Then the combo box's _Change() procedure
just needs to set the text box's .Text property equal to the combo box's
.Text property.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Jay Freedman

unread,
May 21, 2010, 4:36:43 PM5/21/10
to
Sorry, the last part of that is wrong... Instead of the combo box's .Text
value, you need to assign the corresponding value from the invisible second
column.

That brings up another point: If you use a combo box instead of a list box,
there is the possibility that the user typed in a value instead of choosing
one from the list, and in that case there wouldn't be any "corresponding
value from the second column". To prevent this, you need to set the combo
box's .MatchRequired property to True.

Jay Freedman wrote:
> Take a look at the article
> http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm, especially
> the code samples labeled "Excel Example" 1 through 3 that show how to
> get the data from Excel into the .List member of the combo box.
> Although Greg uses a list box, the same technique works with a combo
> box (which is really just the combination of a list box and an edit
> box).
> Your combo box's list should display only the first column, but it
> can also invisibly store the second column. Then the combo box's
> _Change() procedure just needs to set the text box's .Text property
> equal to the combo box's .Text property.
>
>

Todd

unread,
May 24, 2010, 10:17:53 AM5/24/10
to
Thank you, Jay. I'll try to work on this today, if a Monday will allow!

Todd

"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:OBe0UVS%23KH...@TK2MSFTNGP06.phx.gbl...

Todd

unread,
May 24, 2010, 3:58:56 PM5/24/10
to
My combobox is populating properly, but I'm still stuck on the second part.
Jay is right... I need to "assign the corresponding value from the invisible
second
column." So, how do I do that?

"Jay Freedman" <jay.fr...@verizon.net> wrote in message
news:OBe0UVS%23KH...@TK2MSFTNGP06.phx.gbl...

Doug Robbins - Word MVP

unread,
May 24, 2010, 5:30:32 PM5/24/10
to
Set the .BoundColumn attribute of the combobox to the second column when you
want to get the value in that column.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Todd" <To...@christianfp.com> wrote in message
news:8E35A262-4227-43A6...@microsoft.com...

Todd

unread,
May 28, 2010, 8:44:50 AM5/28/10
to
Thanks, Doug. I think I'm on my way now!

Todd

"Doug Robbins - Word MVP" <d...@REMOVECAPSmvps.org> wrote in message
news:DD57E76D-B7B0-4FB1...@microsoft.com...

0 new messages