+ Reply to Thread
Results 1 to 5 of 5

VBA help needed to auto format date column and remove "A" text

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-30-2011
    Location
    Doha
    MS-Off Ver
    MS office 365
    Posts
    701

    VBA help needed to auto format date column and remove "A" text

    Folks,

    Please help me to auto format the Column "D" and "E" to "DD-MM-YY" format automatically and remove "A" Character. I have attached the excel file for better explains.


    Thank you so much in advance
    Last edited by krjoshi; 02-16-2014 at 04:16 PM.
    Cheers,

    Joshi
    Being with a winner makes you a winner

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: VBA help needed to auto format date column and remome "A" text

    Hi Joshi,

    You have some Text instead of numbers for your finish date/times. See if the helper columns lets you understand how I fixed these problems.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    10-30-2011
    Location
    Doha
    MS-Off Ver
    MS office 365
    Posts
    701

    Re: VBA help needed to auto format date column and remome "A" text

    Hi Marvin,
    Thanks for your help and advice. Can you please help me to build a macro to replace the formula since the row data will vary frequenlty (then I need to fill down the formula al the time) , and some times both Start and Finish date columns will have "A" text. Please help me to fix these issues.

    Thanks,
    Joshi
    Last edited by krjoshi; 02-16-2014 at 03:59 PM.

  4. #4
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: VBA help needed to auto format date column and remove "A" text

    Hi krjoshi,

    added an event procedure which automatically formats all new dates that you add, as well as a macro that formats the existing. See the attached and try if it works for you.

    In Module1:
    Sub FormatDates()
    
        Dim rng As Range, c As Range
        
        With Sheets("Sheet1")
            Set rng = .Range("A1").CurrentRegion
            Set rng = Application.Intersect(rng, rng.Offset(2), .Columns("D:E"))
        End With
    
        For Each c In rng
            If Right(c.Value, 2) = " A" Then c.Value = Replace(c.Value, " A", "")
            If c.NumberFormat <> "DD-MM-YY" Then c.NumberFormat = "DD-MM-YY"
        Next c
    
    End Sub
    In the Sheet1 module:
    Private Sub Worksheet_change(ByVal Target As Range)
    
        If Application.Intersect(Target, Columns("D:E")) Is Nothing Then Exit Sub
    
        Application.EnableEvents = False
        With Target
            If Right(.Value, 2) = " A" Then .Value = Replace(.Value, " A", "")
            If .NumberFormat <> "DD-MM-YY" Then .NumberFormat = "DD-MM-YY"
        End With
        Application.EnableEvents = True
    
    End Sub
    Regards, berlan
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    10-30-2011
    Location
    Doha
    MS-Off Ver
    MS office 365
    Posts
    701

    Re: VBA help needed to auto format date column and remove "A" text

    Hi Berlan and MarvinP, thanks for your time and great help. Thank you so much once again.

    Joshi

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Date format of just "st" "nd" "rd" and "th" with text included
    By notrandom in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-10-2013, 05:45 PM
  2. [SOLVED] If there is any text in column "A$" on "sheet1" then move cell to column "A$" on "sheet2"
    By ckgeary in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2013, 08:28 PM
  3. [SOLVED] Formula needed to display "Pass" or "Fail" if a column contains any values other than "yes
    By andreindy in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-26-2013, 05:49 PM
  4. Help Needed to get Filters Using "Include" and "Exclude" multiple values on one column.
    By alfykunable in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2012, 04:03 AM
  5. Replies: 0
    Last Post: 08-22-2012, 03:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1