×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

[Excel] Using the Find method

[Excel] Using the Find method

[Excel] Using the Find method

(OP)
I hate to ask these kind of questions, but...  why doesn't this work?  I'm getting a compile error on the Set dtFindMe line.


Sub FindDate()
  Dim dtFindMe As Date
  Dim rgFoundMe As Range
  
  Set dtFindMe = DateSerial(2002, 2, 22)
  Set rgFoundMe = Range("A:A").Find(what:=dtFindMe)
  
  If rgFoundMe Is Nothing Then
    Exit Sub
  End If
  
  rgFoundMe.Font.Bold = True
  
End Sub


Any help would be appreciated.
SM

RE: [Excel] Using the Find method

DateSerial returns a Variant and you only need to use the Set statement for objects, not variables.

  Dim dtFindMe As Date
  
  dtFindMe = CDate(DateSerial(2002, 2, 22))

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: [Excel] Using the Find method

(OP)
Does, then, the following line not need its Set?  Or is a range not an object?


Set rgFoundMe = Range("A:A").Find(what:=dtFindMe)


SM

RE: [Excel] Using the Find method

Yes, the Find method returns a Range object, so it would require the set statement.

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: [Excel] Using the Find method

The code works in this variant:

  Dim dtFindMe As Date
  Dim rgFoundMe As Range
  
  dtFindMe = DateSerial(2002, 2, 22)

  Set rgFoundMe = Range("A:A").Find(what:=dtFindMe)
  
  If rgFoundMe Is Nothing Then
    Exit Sub
  End If
  
  rgFoundMe.Font.Bold = True
  
End Sub

dtFindMe it is not an object and you do not have to use "Set". !!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources