View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default For Each Next woes

Sub aa()
Dim rng As Range
Dim Target As Range
Dim AskDate As String
Set rng = Range("B17:AK48")
Do
AskDate = InputBox("Enter Date")
If AskDate = "" Then Exit Sub
If Not IsDate(AskDate) Then Exit Sub
MsgBox CDate(AskDate), Application.CountIf(rng, AskDate)
Loop Until Application.CountIf(rng, CDate(AskDate)) 0
For Each Target In rng
If Int(Target.Value2) = CLng(CDate(AskDate)) Then
Target.Select
Exit For
End If
Next

End Sub

--
Regards,
Tom Ogilvy




"AZ Analog" wrote in message
...
Good day!
I'm having difficulty with the proper syntax for the following operation:

Dim AskDate as Date
Dim Target as Variant

For Each Target in [B17:AK48]
AskDate = InputBox("Enter Date")
If Target = AskDate then
Target . Select
Exit For
Else
Endif
Next Target


Here is what I am trying to do. The user inputs a date, the macro

searches
the defined array for that user-input date. If the date is found, the
selection becomes that particular cell. If the date is not found, the

user
is prompted to enter a date in again. This process repeats until an input
date matches a date within the given array. I've messed with syntax for a
couple hours, so I'm wondering if someone would be kind enough to give me

a
push in the right direction. Thank you for your time!