Consulting

Results 1 to 7 of 7

Thread: Solved: Minutes and Seconds Validation

  1. #1

    Red face Solved: Minutes and Seconds Validation

    'Unique TT NamedRanges
    With Range("TT")
        .Locked = False
        .Validation.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="00:01", Formula2:="99:99"
        .Validation.IgnoreBlank = False
        .Validation.ErrorTitle = "Time Error"
        .Validation.ErrorMessage = "Please Enter Minutes & Seconds in this format 23:59"
        .Validation.ShowError = True
    End With
    What I want to achieve is with range "TT" I want the user to be only able to put in minutes and seconds in the format 23:59 (twenty three minutes and 59 seconds) ... i cant get it to do that , the nearest ive got is with a decimal point rather than : , but the problem with decimal it accepts whole numbers so someone could potentionally type in 23 and it would accept it and display it as 23 rather than 23:00 (23 minutes 0 seconds)

    can and one help ....????

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim cell As String
    'Unique TT NamedRanges
    With Range("TT")
    cell = .Cells(1, 1).Address(False, False)
    .Locked = False
    .Validation.Delete
    .Validation.Add Type:=xlValidateCustom, _
    AlertStyle:=xlValidAlertStop, _
    Operator:=xlGreater, _
    Formula1:="=AND(" & cell & ">=TIME(0,0,1)," & cell & "<=TIME(23,59,59))"
    .Validation.IgnoreBlank = False
    .Validation.ErrorTitle = "Time Error"
    .Validation.ErrorMessage = "Please Enter Minutes & Seconds in this format 23:59"
    .Validation.ShowError = True
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Hi, guidance

    Could you explain the code, Why dim cell as string ??

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Because I am getting the address of the first cell in the range TT, and that is a string.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5

    ok..

    Is there anywhere I can learn more vba script writing?

  6. #6
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,200
    Location
    This very forum is a wealth of info.. you can look through the knowledge base, you can look through articles, you can look at other peoples problems and solutions to try and understand how they were solved. Basicly there is alot of readind to do, i have gained alot from this forum and its free.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  7. #7
    Thanks mate, I will search the knowledge base more before I post

Posting Permissions

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