Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Conditional Find

I wish to search a selected range of cells containing dates for any desired
date. If the date I'm looking for is found, I want to run certain code. If
it's not found, then I'll run different code.

For example, if I'm searching for 3/15/08 and a match is found among the
selected range of cells, perform certain code. If this date is not found,
perform this other code. Thanks in advance for your help!
--
Steve C
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Conditional Find

Hi Steve

You could try something like the code below that should give you an
idea of how to do what your after. I added this code to a user button
but it could be amended to fit what ever you like.

Option Explicit
Dim MyDate As Date 'declare your variable as a date

Private Sub CommandButton1_Click()

MyDate = InputBox("Please Enter a Date", "Date Finder") 'enter a date
to find

On Error Resume Next 'add this to trap the error on date not found

With Range("TestRng") 'set the range to search

.Find(What:=MyDate, LookAt:=xlWhole).Activate 'if found activate
the cell

If ActiveCell.Value = MyDate Then ' if active cell matches
your date do this

MsgBox "Run the code for a finding a date"

Else 'if it doesn't match then do this

MsgBox "Run the code for a date not found"

End If

End With

End Sub

Hope this helps

S



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Conditional Find

Check out the example in the VBA help. In the VBA editor, type Find,
then F1.

I think this is what you're looking for.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Conditional Find

Thanks! That works nicely.
--
Steve C


"Incidental" wrote:

Hi Steve

You could try something like the code below that should give you an
idea of how to do what your after. I added this code to a user button
but it could be amended to fit what ever you like.

Option Explicit
Dim MyDate As Date 'declare your variable as a date

Private Sub CommandButton1_Click()

MyDate = InputBox("Please Enter a Date", "Date Finder") 'enter a date
to find

On Error Resume Next 'add this to trap the error on date not found

With Range("TestRng") 'set the range to search

.Find(What:=MyDate, LookAt:=xlWhole).Activate 'if found activate
the cell

If ActiveCell.Value = MyDate Then ' if active cell matches
your date do this

MsgBox "Run the code for a finding a date"

Else 'if it doesn't match then do this

MsgBox "Run the code for a date not found"

End If

End With

End Sub

Hope this helps

S




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
Challenge with conditional find Vic[_4_] Excel Programming 3 May 13th 07 02:40 AM
Conditional FIND and REPLACE wisynco Excel Worksheet Functions 0 June 7th 06 06:46 PM
conditional statement to find more than one value ?? gaba Excel Programming 2 October 29th 04 02:04 AM
Conditional find Ramesh[_2_] Excel Programming 1 October 28th 03 10:38 PM
Conditional find Ramesh[_2_] Excel Programming 1 October 22nd 03 03:47 PM


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