Consulting

Results 1 to 2 of 2

Thread: Formating date delimiters in real time

  1. #1
    VBAX Newbie
    Joined
    Jan 2016
    Posts
    1
    Location

    Formating date delimiters in real time

    I have already formated a column to Date and wish users to enter the date using the forward slash delimiters, however, users are sometimes
    entering the date using the dot(full stop) as a delimiter.
    I would like to force the dot to a forward slash as it is entered. However, if this involves the use of API I am NOT familiar with this use of it.
    As an alternative to the above the dot delimiter can be changed to a forward slash as the user exits the cell for the next cell if this makes the coding easier.
    It should be noted that some users use a leading zero for single digits and some do not that is why I thought it would be better to concentrate on the date delimiters.
    ie 01.01.2016 to 01/01/2016 or 1.1.2016 to 01/01/2016

    Finally, as if I havent made my request hard enough, I would like to be able to hide this code from the user.

    Any help on some VBA code to do the above would be greatly appreciated.

    Regards
    Doc666

  2. #2
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,710
    Location
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Columns("DateColumn"), Target) Is Nothing Then FormatDate Target
    'Edit "DateColumn" To the Column Number or use _
      "Intersect(Range("X:X"), Target)" _
      where "X:X" is the Column Address
    
    End Sub
    
    
    Sub FormatDate(Target As Range)
    If Target.Count > 1 Or Not IsDate(Target) Then Exit Sub
    Target = Format(Target, "ss/mm/yyyy")
    End Sub
    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

Posting Permissions

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