Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Comboboxes on userforms

I have a combobox on a userform, well call it "cbxHeadache1"

and a range well call "range1". Range 1 is a multicolumn range
existing on a worksheet of names, addresses, etc. Call it ColA, ColB,
ColC, etc.

The premise is that when you select a company name from the Combobox,
all of their address data populates to the various text boxes on the
userform.

What is the easiest way to program this in VBA, so that when
cbxHeadache change event fires, VBA pulls the data appropriate to the
row/selection for the combobox value, from the various columns to the
appropriate textbox on the userform?

TIA

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Comboboxes on userforms

Your combobox can support multiple columns--and all the columns don't have to be
visible. So you can pick up your array of values from the range (hiding columns
2 and 3) and then use those hidden values to populate the textboxes.

I put a commandbutton (cancel), 2 textboxes and a combobox on a userform.

This was the code behind the userform:

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub ComboBox1_Change()
'clear out old
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""

With Me.ComboBox1
If .ListIndex < 0 Then
'nothing selected, do nothing
Else
Me.TextBox1.Value = .List(.ListIndex, 1)
Me.TextBox2.Value = .List(.ListIndex, 2)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range
Dim LastRow As Long

With Worksheets("sheet1")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set myRng = .Range("A1:C" & LastRow)
End With

With Me.ComboBox1
.ColumnCount = 3
.ColumnWidths = ";0;0"
.List = myRng.Value
End With
End Sub




wrote:

I have a combobox on a userform, well call it "cbxHeadache1"

and a range well call "range1". Range 1 is a multicolumn range
existing on a worksheet of names, addresses, etc. Call it ColA, ColB,
ColC, etc.

The premise is that when you select a company name from the Combobox,
all of their address data populates to the various text boxes on the
userform.

What is the easiest way to program this in VBA, so that when
cbxHeadache change event fires, VBA pulls the data appropriate to the
row/selection for the combobox value, from the various columns to the
appropriate textbox on the userform?

TIA


--

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
comboboxes [email protected] uk Excel Discussion (Misc queries) 1 December 6th 09 05:07 PM
Comboboxes mr-bear New Users to Excel 1 November 21st 06 10:05 AM
comboboxes, userforms and class modules natanz[_2_] Excel Programming 3 November 29th 05 02:59 PM
ComboBoxes Ryan Excel Programming 0 April 14th 04 10:56 PM
Comboboxes Angeliki Excel Programming 1 March 3rd 04 12:00 PM


All times are GMT +1. The time now is 12:22 AM.

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

About Us

"It's about Microsoft Excel"