Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Add 2nd condition to Find
The below code searches for the Value that was selected in Listbox2.
But i have found that there maybe more than 1 value in that column (C) If there is i Always gain the same data. I placed the (<=== HERE) line of code to try to include a 2nd condition to ensure the correct data is selected, but even though there IS a match, i get NO DATA at all. The value in rngFound.Offset(0,15) is Always a date (dd/mm/yyyy) and the value in rngfound is Always Text. Dim rngFound As Range On Error Resume Next Sheets("Data2").Visible = True Sheets("Data2").Unprotect With Worksheets("Data2").Range("C:C") Set rngFound = .Find(What:=ListBox2.Value, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False) If rngFound.Value < "" And ListBox3.Value = rngFound.Offset(0, 15).Value Then <=== HERE .... .... .... end if end with Why does this not find the data with the 2nd condition ? Corey.... |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Add 2nd condition to Find
A couple of things. rngFound will be the first matching item found. You did
not post the code for your loop so it is hard to comment. Secondly Listboxes return text values where as the cell contains a date. You are comparing apples and oranges. You are probalby best off to compare text to text something like this... If ListBox3.Value = format(rngFound.Offset(0, 15).Value, "dd/mm/yyyy") Then so I would expect to see somthing like this Dim rngFound As Range Dim strFirstAddress As String Dim blnFound As Boolean Sheets("Data2").Visible = True Sheets("Data2").Unprotect With Worksheets("Data2").Range("C:C") Set rngFound = .Find(What:=ListBox2.Value, _ After:=.Cells(1), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ Matchbyte:=False) If Not rngFound Is Nothing Then strFirstAddress = rngFound.Address Do If ListBox3.Value = Format(rngFound.Offset(0, 15).Value, "dd/mm/yyyy") Then blnFound = True Exit Do End If Set rngFound = .FindNext(rngFound) Loop Until rngFound.Address = strFirstAddress End If If blnFound = True Then MsgBox rngFound.Address End With -- HTH... Jim Thomlinson "Corey" wrote: The below code searches for the Value that was selected in Listbox2. But i have found that there maybe more than 1 value in that column (C) If there is i Always gain the same data. I placed the (<=== HERE) line of code to try to include a 2nd condition to ensure the correct data is selected, but even though there IS a match, i get NO DATA at all. The value in rngFound.Offset(0,15) is Always a date (dd/mm/yyyy) and the value in rngfound is Always Text. Dim rngFound As Range On Error Resume Next Sheets("Data2").Visible = True Sheets("Data2").Unprotect With Worksheets("Data2").Range("C:C") Set rngFound = .Find(What:=ListBox2.Value, After:=.Cells(1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, Matchbyte:=False) If rngFound.Value < "" And ListBox3.Value = rngFound.Offset(0, 15).Value Then <=== HERE .... .... .... end if end with Why does this not find the data with the 2nd condition ? Corey.... |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
SUMPRODUCT with condition FIND(text) is false | Excel Worksheet Functions | |||
If condition to find Target | Excel Discussion (Misc queries) | |||
How to find first row where condition is true? | Excel Discussion (Misc queries) | |||
?How can I find the maximum column with condition | Excel Discussion (Misc queries) | |||
Find and replace with condition | Excel Discussion (Misc queries) |