Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Challenge with conditional find | Excel Programming | |||
Conditional FIND and REPLACE | Excel Worksheet Functions | |||
conditional statement to find more than one value ?? | Excel Programming | |||
Conditional find | Excel Programming | |||
Conditional find | Excel Programming |