Consulting

Results 1 to 2 of 2

Thread: VBA - finding date in another worksheet

  1. #1

    VBA - finding date in another worksheet

    Hi

    I would love some help on the below.

    FindDate = 29/02/2016 (this is defined by C3 in the "INPUTS" tab).

    When I run the macro below, I get a message box and "nope", whereas I'd like the macro to select cell AI9 of the "Corporate" tab which also has the date 29/02/2016 in it. I've probably not explained everything you need to know but if not, then please tell me why the macro isn't doing what I want it to.

    Many thanks!

    Sub Macro2()
    Dim MI As Workbook
    Dim DataRange1 As Range
    Dim FindDate As Date
    Dim Loc As Range
    Set MI = ThisWorkbook
    Set DataRange1 = MI.Worksheets("Corporate").Range("9:9")
    FindDate = MI.Sheets("INPUTS").Range("C3")
    
    If Trim(FindDate) <> "" Then
        With DataRange1
            Set Loc = .Find(what:=FindDate)
            If Not Loc Is Nothing Then
            Application.Goto Loc, True
        Else
        MsgBox "nope"
        End If
    End With
    End If
    
    End Sub
    Last edited by SamT; 03-20-2016 at 07:24 PM. Reason: added CODE Tags using the Editor # Icon

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Try
    .Find(lookIn:=xlValues, ...)

    Also try
    IF IsDate(Trim(FindDate)) Then

    Finally, try adding this to your code
    '
    ' 
    Dim X, Y
    X = FindDate
    Y = Worksheets("Corporate").Range("AI9")
    '
    '
    '
    Step thru the code by pressing F8 and hover the mouse over X and Y after the Moving Yellow Highlight passes them
    Last edited by SamT; 03-20-2016 at 07:43 PM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •