+ Reply to Thread
Results 1 to 5 of 5

VBA to replace first two characters in dd/mm/yyyy with "01"

  1. #1
    Registered User
    Join Date
    12-29-2017
    Location
    South Africa
    MS-Off Ver
    Office Pro 2016
    Posts
    21

    VBA to replace first two characters in dd/mm/yyyy with "01"

    Greetings,

    In the attached file, I've got a bunch of dates set as dd/mm/yyyy. In this case, dd ranges from 01 - 31.

    I'd like all dd to be replaced with 01 only, so that it's essentially 01/mm/yyyy, and still correctly reads as DMY.

    I've manually done the first few in Column B as an example.

    Looking for VBA that can do this.

    Any suggestions appreciated.
    Attached Files Attached Files

  2. #2
    Spammer
    Join Date
    01-08-2015
    Location
    Cali, Colombia
    MS-Off Ver
    365
    Posts
    302

    Re: VBA to replace first two characters in dd/mm/yyyy with "01"

    Hi!

    If you want, you can use just formulas to do it:
    [B2] : =A2-DAY(A2)+1

    Or, with VBA in same range:
    PHP Code: 
    Sub ChangeDate()
        
    uf& = Range("A" Rows.Count).End(xlUp).Row
        Range
    ("a2:a" uf) = Evaluate(Replace("if(a2:a#,a2:a#-day(a2:a#)+1)""#"uf))
    End Sub 
    Check file. Blessings!
    Attached Files Attached Files

  3. #3
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: VBA to replace first two characters in dd/mm/yyyy with "01"

    Please Login or Register  to view this content.

  4. #4
    Forum Expert 63falcondude's Avatar
    Join Date
    08-22-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    6,266

    Re: VBA to replace first two characters in dd/mm/yyyy with "01"

    Here's a formula solution for anyone that may come across this in the future:

    B2 =EOMONTH(A2,-1)+1

  5. #5
    Registered User
    Join Date
    12-29-2017
    Location
    South Africa
    MS-Off Ver
    Office Pro 2016
    Posts
    21

    Re: VBA to replace first two characters in dd/mm/yyyy with "01"

    Thanks everyone! Much appreciated

+ 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. Difference between "mm/dd/yyyy" vs "mm/dd/yyyy;@" formatting
    By lostest in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 03-13-2016, 03:39 PM
  2. [SOLVED] Convert from "general" (YYYYMMDD) to specific "custom" format (YYYY.MM.DD)
    By Ella_p in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-10-2013, 02:23 AM
  3. [SOLVED] Substitute formula - i want to replace cell containing special characters "??????*"
    By karthikskengeri in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-14-2013, 06:21 AM
  4. Replace "illegal database" characters with "_" in one go
    By coreagc in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-05-2013, 03:32 AM
  5. [SOLVED] Need to remove first two characters of column and replace with a "U"
    By arashn in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-23-2012, 06:21 PM
  6. Macro to replace European characters with non "special" English characters?
    By johanna0507 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2012, 09:13 AM
  7. Find & Replace all characters in cell like ";#"
    By chasepes in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-14-2009, 01:58 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