Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 276
Default ListBox Condition Not working for 1st Entry

I have a form with 2 Listboxes
Once a Value is selected from Listbox1, Listbox2 is populated with a value(offset) to the Listbox1 sheet value.

When the user selects the Listbox2 value the below code runs, but when there is 1 entry matching if the user clicks the 1st entry the code does not work. But if the 2nd is chosen the code works.
The code simply places the required data into another sheet(sheet6).


Private Sub ListBox2_Click()
Application.ScreenUpdating = False
With Worksheets("Data")
..Select
Dim rngFound As Range
On Error Resume Next
Sheets("Data").Unprotect
With Worksheets("Data").Range("B:B")
Set rngFound = .Find(What:=ListBox1.Value, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, Matchbyte:=False)
If rngFound.Value < "" And rngFound.Offset(0, -1).Text = ListBox2.Text Then ' <== Condition to ensure the value in Column A was chosen in Listbox1
With Sheet6
.Select
.Range("A100") = rngFound.Value ' <== When both Listbox1 & Listbox2 value are correct, the Listbox1 value(rngFound) is placed into Sheet6.Range("A100")
End With
End If
End With
..Protect
End With
Sheet6.Activate
Application.ScreenUpdating = True
End Sub


I do not understabd WHY the 1st Instance of the values in Listbox2 will NOT place data to Sheet6.

But the 2nd instance will????


--
Corey ....
The Silliest Question is generally
the one i forgot to ask.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default ListBox Condition Not working for 1st Entry

I added code for debugging

Set rngFound = .Find(What:=ListBox1.Value, After:=.Cells(1),
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious, MatchCase:=False, Matchbyte:=False)
if rngFound is Nothing then
Msgbox("Did not find : " & ListBox1.Value & " - Exiting Macro")
exit sub
end if
If rngFound.Value < "" And rngFound.Offset(0, -1).Text = ListBox2.Text
Then ' <== Condition to ensure the value in Column A was chosen in Listbox1


"Corey" wrote:

I have a form with 2 Listboxes
Once a Value is selected from Listbox1, Listbox2 is populated with a value(offset) to the Listbox1 sheet value.

When the user selects the Listbox2 value the below code runs, but when there is 1 entry matching if the user clicks the 1st entry the code does not work. But if the 2nd is chosen the code works.
The code simply places the required data into another sheet(sheet6).


Private Sub ListBox2_Click()
Application.ScreenUpdating = False
With Worksheets("Data")
..Select
Dim rngFound As Range
On Error Resume Next
Sheets("Data").Unprotect
With Worksheets("Data").Range("B:B")
Set rngFound = .Find(What:=ListBox1.Value, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False, Matchbyte:=False)
If rngFound.Value < "" And rngFound.Offset(0, -1).Text = ListBox2.Text Then ' <== Condition to ensure the value in Column A was chosen in Listbox1
With Sheet6
.Select
.Range("A100") = rngFound.Value ' <== When both Listbox1 & Listbox2 value are correct, the Listbox1 value(rngFound) is placed into Sheet6.Range("A100")
End With
End If
End With
..Protect
End With
Sheet6.Activate
Application.ScreenUpdating = True
End Sub


I do not understabd WHY the 1st Instance of the values in Listbox2 will NOT place data to Sheet6.

But the 2nd instance will????


--
Corey ....
The Silliest Question is generally
the one i forgot to ask

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
showing a listbox with last entry as the default Katrina Excel Programming 3 November 8th 06 06:24 AM
Require Cell Entry based on condition Kathy - Lovullo Excel Programming 3 January 13th 06 03:02 PM
Data Entry Listbox Tom Ogilvy Excel Programming 0 January 19th 05 04:03 PM
Different text format on a listbox entry Marcelo[_5_] Excel Programming 2 July 23rd 04 04:38 AM
Disappearing listbox entry Stuart[_5_] Excel Programming 1 February 26th 04 02:35 PM


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