Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Retaining focus on a textbox / listbox item pair after validation = false. | Excel Programming | |||
Copying data from a listbox to a textbox | Excel Programming | |||
Listbox problem | Excel Discussion (Misc queries) | |||
Listbox problem | Excel Programming | |||
Populating TextBox Value--using ListBox | Excel Programming |