Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default find works very oddly

Hi folks,

following code works somtimes, sometimes it doesn't:

Dim foundRange As Range, dateRange As Range
Dim cellAddr As String, dateVal As Date, workingDay As String

workingDay = "02.05.07"
Set dateRange = ThisWorkbook.Worksheets("Mai").Range("D5:D36")
With dateRange
Set foundRange = .Find(what:=format(workingDay, "d") , _
LookIn:=xlValues, _
searchorder:=xlColumns,
_
SearchDirection:=xlNext,
_
LookAt:=xlPart)
Do
If foundRange Is Nothing Then Exit Do ' emergency exit
dateVal = foundRange.Value
Set foundRange = .FindNext(foundRange)
Loop Until dateVal = workingDay ' go 4it until found
End With ' search within a range

Any ideas ??

Thanx for help

chfa

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default find works very oddly

Try this:

Sub TryNow()

Dim foundRange As Range
Dim dateRange As Range
Dim cellAddr As String
Dim dateVal As Date
Dim workingDay As String

workingDay = "05/02/07"

Set dateRange = ThisWorkbook.Worksheets("Mai").Range("D5:D36")
Set foundRange = dateRange.Find(what:=Format(DateValue(workingDay), _
dateRange.Cells(1).NumberFormat), _
LookIn:=xlValues, _
searchorder:=xlColumns, _
SearchDirection:=xlNext, _
LookAt:=xlPart)
If foundRange Is Nothing Then
MsgBox "Not Found"
Else
MsgBox "That date is in " & foundRange.Address
End If

End Sub


Note that workingDay = "02.05.07" did not work for me - The decimal separator isn't valid in VBA,
IIRC, and dates are by default US -centric in VBA - mm/dd/yy....

HTH,
Bernie
MS Excel MVP


"chfa" wrote in message
oups.com...
Hi folks,

following code works somtimes, sometimes it doesn't:

Dim foundRange As Range, dateRange As Range
Dim cellAddr As String, dateVal As Date, workingDay As String

workingDay = "02.05.07"
Set dateRange = ThisWorkbook.Worksheets("Mai").Range("D5:D36")
With dateRange
Set foundRange = .Find(what:=format(workingDay, "d") , _
LookIn:=xlValues, _
searchorder:=xlColumns,
_
SearchDirection:=xlNext,
_
LookAt:=xlPart)
Do
If foundRange Is Nothing Then Exit Do ' emergency exit
dateVal = foundRange.Value
Set foundRange = .FindNext(foundRange)
Loop Until dateVal = workingDay ' go 4it until found
End With ' search within a range

Any ideas ??

Thanx for help

chfa



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default find works very oddly

Problems I have encountered with Find Method:
1. Cells not all formatted with the same format.
2. Saved values hanging around from a different Find. Per the Find
Method Help, "The settings for LookIn, LookAt, SearchOrder, and
MatchByte are saved each time you use this method. If you don't
specify values for these arguments the next time you call the method,
the saved values are used."
3. Not all the cells to be searched included in the range being
searched.

Carl.

On May 2, 3:30 am, chfa wrote:
Hi folks,

following code works somtimes, sometimes it doesn't:

Dim foundRange As Range, dateRange As Range
Dim cellAddr As String, dateVal As Date, workingDay As String

workingDay = "02.05.07"
Set dateRange = ThisWorkbook.Worksheets("Mai").Range("D5:D36")
With dateRange
Set foundRange = .Find(what:=format(workingDay, "d") , _
LookIn:=xlValues, _
searchorder:=xlColumns,
_
SearchDirection:=xlNext,
_
LookAt:=xlPart)
Do
If foundRange Is Nothing Then Exit Do ' emergency exit
dateVal = foundRange.Value
Set foundRange = .FindNext(foundRange)
Loop Until dateVal = workingDay ' go 4it until found
End With ' search within a range

Any ideas ??

Thanx for help

chfa


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
ActiveX Control Text Rendering Oddly frankcatvertek Excel Discussion (Misc queries) 0 September 20th 10 06:54 PM
Works spreadsheet-find circular ref. dino Excel Worksheet Functions 1 October 22nd 07 05:52 PM
Select Case Behaving Oddly Kris_Wright_77 Excel Programming 3 June 6th 06 07:06 PM
OFFSET behaving oddly Ryan Poth Excel Worksheet Functions 2 May 30th 06 07:29 AM
=ISODD Behaving Oddly Craig[_15_] Excel Programming 5 April 30th 04 08:59 PM


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