Consulting

Results 1 to 6 of 6

Thread: static today date function based on 2 criteria

  1. #1
    VBAX Mentor
    Joined
    May 2010
    Location
    London
    Posts
    307
    Location

    static today date function based on 2 criteria

    Hi All ,

    I use below formula to update the date based on Yes/No criteria. However I need a static date. When I use Y/N in A5 then F5 should reflect the date data entry is done and stay the same. Is there any way I could get it done by a formula or any other ideas?

    =IF(OR((A5="Y"),(A5="N")),TODAY(),"")

    Cheers
    B.
    Sub Learning VBA()

    Do
    Practice Most Useful VBA Examples
    Loop Until Become an Expert in VBA

    End Sub

  2. #2
    VBAX Mentor
    Joined
    May 2010
    Location
    London
    Posts
    307
    Location
    I found this script on another forum and wanted to share for those who need a similar solution I had. It creates today date as static based on the value entered in a specific column.


    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Then Exit Sub
    
            If Not Intersect(Target, Range("A2:A100")) Is Nothing Then
    
                With Target(1, 6)
    
                    .Value = Date
    
                    .EntireColumn.AutoFit
    
                End With
    
            End If
    
    End Sub
    Sub Learning VBA()

    Do
    Practice Most Useful VBA Examples
    Loop Until Become an Expert in VBA

    End Sub

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    With Target(1, 6)
    What is the function/purpose/meaning of the (1, 6)?

    Never mind, I see it is shorthand for Target.Offset(0, 5)
    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

  4. #4
    VBAX Mentor
    Joined
    May 2010
    Location
    London
    Posts
    307
    Location
    yes it is offset function.
    Sub Learning VBA()

    Do
    Practice Most Useful VBA Examples
    Loop Until Become an Expert in VBA

    End Sub

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Not exactly

    Target.Offset(-1, -5) works
    Target(-1, -6) fails

    Still, it's a good shorthand to be aware of.
    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

  6. #6
    VBAX Mentor
    Joined
    May 2010
    Location
    London
    Posts
    307
    Location
    sure you know better than me I'm a newbie. Thanks for the explanation.
    Sub Learning VBA()

    Do
    Practice Most Useful VBA Examples
    Loop Until Become an Expert in VBA

    End Sub

Posting Permissions

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