Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Listbox - Text Field

I have a worksheet that has three columns and two row of data

Orange Score Missed
Red Score Target

I have a form with a listbox and two text boxes

The list box is populated with Orange and Red by using the below code

With Sheets("Sheet1")
Set r = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
For Each c In r
ListBox1.AddItem c
Next c
End With

I want to be able to click on Orange and populate the text box with the
corresponding values.

Can someone point me in the right direction?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Listbox - Text Field

Try something like this:

Sub ListBox1_Change()
Dim rng As Range
Set rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp)) _
.Find(ListBox1)
TextBox1 = rng.Offset(, 1)
TextBox2 = rng.Offset(, 2)
End Sub

You may be better off using a multi-column ListBox.

--

Vasant

"dthmtlgod" wrote in message
...
I have a worksheet that has three columns and two row of data

Orange Score Missed
Red Score Target

I have a form with a listbox and two text boxes

The list box is populated with Orange and Red by using the below code

With Sheets("Sheet1")
Set r = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
For Each c In r
ListBox1.AddItem c
Next c
End With

I want to be able to click on Orange and populate the text box with the
corresponding values.

Can someone point me in the right direction?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Listbox - Text Field

Thank you sir.

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Try something like this:

Sub ListBox1_Change()
Dim rng As Range
Set rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp)) _
.Find(ListBox1)
TextBox1 = rng.Offset(, 1)
TextBox2 = rng.Offset(, 2)
End Sub

You may be better off using a multi-column ListBox.

--

Vasant

"dthmtlgod" wrote in message
...
I have a worksheet that has three columns and two row of data

Orange Score Missed
Red Score Target

I have a form with a listbox and two text boxes

The list box is populated with Orange and Red by using the below code

With Sheets("Sheet1")
Set r = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
For Each c In r
ListBox1.AddItem c
Next c
End With

I want to be able to click on Orange and populate the text box with the
corresponding values.

Can someone point me in the right direction?






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Listbox - Text Field

you could as easily used VLOOKUP() on the sheet.
As this is a programming group

TextBox1.Text = _
WorksheetFunction.VLookup(ListBox1.Value, Range("A1:c2"), 2, False)
TextBox2.Text = _
WorksheetFunction.Function.VLookup(ListBox1.Value, Range("A1:c2"), 3,
False)


"Vasant Nanavati" wrote:

Try something like this:

Sub ListBox1_Change()
Dim rng As Range
Set rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp)) _
.Find(ListBox1)
TextBox1 = rng.Offset(, 1)
TextBox2 = rng.Offset(, 2)
End Sub

You may be better off using a multi-column ListBox.

--

Vasant

"dthmtlgod" wrote in message
...
I have a worksheet that has three columns and two row of data

Orange Score Missed
Red Score Target

I have a form with a listbox and two text boxes

The list box is populated with Orange and Red by using the below code

With Sheets("Sheet1")
Set r = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
For Each c In r
ListBox1.AddItem c
Next c
End With

I want to be able to click on Orange and populate the text box with the
corresponding values.

Can someone point me in the right direction?





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Listbox - Text Field

"Patrick Molloy" wrote in message
...
you could as easily used VLOOKUP() on the sheet.


Now why didn't I think of that? :)

Regards,

Vasant


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
Trouble sorting first by a dates field and then by a text field. trainer07 Excel Discussion (Misc queries) 1 December 6th 06 12:25 AM
Multi-field listbox in an Excel form Lee S. Excel Discussion (Misc queries) 0 September 14th 06 10:19 PM
Changing a text field to a date field juliet New Users to Excel 4 February 21st 06 09:52 PM
Fill a Listbox with Values from a Pivot Table Field - an Example DataFreakFromUtah Excel Programming 0 February 12th 04 04:12 PM
HELP!! Populate text in single XL field, or bulk copy text into 1 field filmfatale[_2_] Excel Programming 0 December 9th 03 02:30 PM


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