Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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
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
SUMPRODUCT with condition FIND(text) is false Go Bucks!!![_2_] Excel Worksheet Functions 2 October 7th 09 04:56 PM
If condition to find Target Karthik Excel Discussion (Misc queries) 1 May 23rd 09 10:49 AM
How to find first row where condition is true? WhatsUp31415 Excel Discussion (Misc queries) 6 May 21st 09 12:11 PM
?How can I find the maximum column with condition SAM SEBAIHI Excel Discussion (Misc queries) 4 February 9th 07 05:53 AM
Find and replace with condition Stuart Excel Discussion (Misc queries) 5 July 26th 05 12:47 PM


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