LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default listbox and textbox problem

I don't understand why this is happening. I have a form with a listbox and
four textboxex. when an value is selected in the listbox, the 4 textboxes
need to show data (vehicle information) from the same row as the selected
value.
it works.... sort of. if I have the vehicle information sheet selected,
everything works fine, but if any other sheet is selected, the values for the
text boxes come from there. here is the code i have in the userform:


Private Sub CommandButton1_Click()
TextBox1 = Clear
TextBox2 = Clear
TextBox3 = Clear
TextBox4 = Clear
AddTicket.Hide
End Sub

Private Sub CommandButton2_Click()
Call Add_Ticket
End Sub

Private Sub ListBox1_Change()
With Sheets("Sheet2").Range("A:A,E:E")
Dim lastrow As Long, a As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For a = lastrow To 2 Step -1
If Cells(a, 1).Text = ListBox1.Text Then
If Cells(a, 2).Text = "" Then
TextBox1.Text = "No Info Availiable"
Else: TextBox1.Text = Cells(a, 2).Text
End If
If Cells(a, 3).Text = "" Then
TextBox2.Text = "No Info Availiable"
Else: TextBox2.Text = Cells(a, 3).Text
End If
If Cells(a, 4).Text = "" Then
TextBox3.Text = "No Info Availiable"
Else: TextBox3.Text = Cells(a, 4).Text
End If
If Cells(a, 5).Text = "" Then
TextBox4.Text = "No Info Availiable"
Else: TextBox4.Text = Cells(a, 5).Text
End If
End If
Next
End With
End Sub

Private Sub UserForm_Initialize()
Dim ListCellreasons As Range
Dim listcellofficers As Range
Dim listcellowner As Range
With Sheets("sheet2").Range("A:A,C:C")
For Each listcellowner In Range("Owner")
If listcellowner.Value < "" Then
ListBox1.AddItem listcellowner.Value
End If
Next
For Each listcellofficers In Range("officers")
If listcellofficers.Value < "" Then
ListBox2.AddItem listcellofficers.Value
End If
Next
For Each ListCellreasons In Range("reasons")
If ListCellreasons.Value < "" Then
ListBox3.AddItem ListCellreasons.Value
End If
Next
End With
End Sub

TIA
 
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
Retaining focus on a textbox / listbox item pair after validation = false. chatterbox Excel Programming 2 April 4th 06 11:42 AM
Copying data from a listbox to a textbox Kevin Vaughn Excel Programming 2 March 3rd 06 11:26 PM
Listbox problem browie Excel Discussion (Misc queries) 1 August 22nd 05 11:44 AM
Listbox problem browie Excel Programming 1 August 22nd 05 11:44 AM
Populating TextBox Value--using ListBox jpendegraft[_15_] Excel Programming 1 May 2nd 04 03:53 AM


All times are GMT +1. The time now is 02:06 PM.

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"