Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default FIND function driving me nuts

I've been trying to get a FIND working in Excel 2003 which I remember
working fine earlier, but for some reason this attempt has been an
effort in futility. Here's the code generated by recording a macro and
CTRL-F to find the text I'm looking for:

Cells.Find(What:="2005.12.07", After:=ActiveCell, LookIn:=xlValues,
_
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Running that code immediately after generating it returns an error! So
does every attempt at using it. I cannot believe that I've discovered
a bug. It works fine from the UI, but dies in VBA.

HELP!

Thanks;
Duncan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default FIND function driving me nuts

Give this a try...

dim rng as range

set rng = activesheet.Cells.Find(What:="2005.12.07", After:=ActiveCell,
LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)

if rng is nothing then
msgbox "Sorry not found..."
else
rng.select
end if
--
HTH...

Jim Thomlinson


"Duncan A. McRae" wrote:

I've been trying to get a FIND working in Excel 2003 which I remember
working fine earlier, but for some reason this attempt has been an
effort in futility. Here's the code generated by recording a macro and
CTRL-F to find the text I'm looking for:

Cells.Find(What:="2005.12.07", After:=ActiveCell, LookIn:=xlValues,
_
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Running that code immediately after generating it returns an error! So
does every attempt at using it. I cannot believe that I've discovered
a bug. It works fine from the UI, but dies in VBA.

HELP!

Thanks;
Duncan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default FIND function driving me nuts

Dates and VBA are trouble.

I'd try this:

dim FoundCell as range
set foundcell = Cells.Find(What:=dateserial(2005,12,07), _
After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

if foundcell is nothing then
msgbox "failed"
else
foundcell.activate
end if



"Duncan A. McRae" wrote:

I've been trying to get a FIND working in Excel 2003 which I remember
working fine earlier, but for some reason this attempt has been an
effort in futility. Here's the code generated by recording a macro and
CTRL-F to find the text I'm looking for:

Cells.Find(What:="2005.12.07", After:=ActiveCell, LookIn:=xlValues,
_
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Running that code immediately after generating it returns an error! So
does every attempt at using it. I cannot believe that I've discovered
a bug. It works fine from the UI, but dies in VBA.

HELP!

Thanks;
Duncan


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default FIND function driving me nuts

Try something like:

Dim dt as Date
Dim rng as Range

dt = DateValue("12/07/2005")
set rng = cells.Find(what:=clng(dt), After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If rng is nothing then
msgbox "Not found"
exit sub
End if

--
Regards,
Tom Ogilvy



"Duncan A. McRae" wrote in message
oups.com...
I've been trying to get a FIND working in Excel 2003 which I remember
working fine earlier, but for some reason this attempt has been an
effort in futility. Here's the code generated by recording a macro and
CTRL-F to find the text I'm looking for:

Cells.Find(What:="2005.12.07", After:=ActiveCell, LookIn:=xlValues,
_
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Running that code immediately after generating it returns an error! So
does every attempt at using it. I cannot believe that I've discovered
a bug. It works fine from the UI, but dies in VBA.

HELP!

Thanks;
Duncan



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default FIND function driving me nuts

rng still comes back empty (= nothing).



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default FIND function driving me nuts

Nicely done! This whole time I thought I was looking at a string, when
in fact it was a date. I thank you, sir!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default FIND function driving me nuts

Here's what I'm going with:

Dim FoundCell As Range
Set FoundCell = Cells.Find(Date)

If FoundCell Is Nothing Then
MsgBox "failed"
Else
FoundCell.Activate
End If

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default FIND function driving me nuts

..Find remembers the last parms that were passed to it--either in code or by the
user. I'd explicitly specify each of those .find parms if I were you.

And if you ever have trouble...

Set FoundCell = Cells.Find(clng(date), ......

may help.


"Duncan A. McRae" wrote:

Here's what I'm going with:

Dim FoundCell As Range
Set FoundCell = Cells.Find(Date)

If FoundCell Is Nothing Then
MsgBox "failed"
Else
FoundCell.Activate
End If


--

Dave Peterson
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
Need Help, this is driving me nuts heitorfjr Excel Discussion (Misc queries) 2 January 15th 06 03:10 PM
Today function is driving me nuts Danny J Excel Worksheet Functions 1 December 5th 05 10:17 PM
question driving me nuts Esaam Excel Discussion (Misc queries) 3 December 1st 05 06:03 PM
Sum and Count are driving me nuts!! Mattrapps Charts and Charting in Excel 1 May 9th 05 07:08 PM
Driving me nuts. Need more nested than 7 Stressed Excel Discussion (Misc queries) 5 April 12th 05 06:20 PM


All times are GMT +1. The time now is 04:00 AM.

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"