+ Reply to Thread
Results 1 to 3 of 3

VBA date change

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    34

    VBA date change

    HI

    i run macro like below - when i do so it changes my dates from Aus (dd/mm/yy) to a US styke (mm/dd/yy) not just the layout but the actual data changes

    any way to stop this??

    Sub Trim()
    Dim cell As Range
    For Each cell In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
    cell = WorksheetFunction.Trim(cell)
    Next cell
    End Sub
    Adrian

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: help with VBA date change

    Hi
    if it happens every time then try this:

    Sub Trim2()
    Dim celL As Range
    For Each celL In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
    
        celL = WorksheetFunction.Trim(celL)
        If IsDate(celL) Then
            If Day(celL) < 13 Then
                ccell = DateSerial(Year(ccell), Month(ccell), Day(ccell))
            End If
        End If
    Next celL
    End Sub

  3. #3
    Registered User
    Join Date
    06-26-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: help with VBA date change

    unfortunately it still does it......with this code.....BUT only if changing the numbers around makes a valid date



    eg


    13/02/2019 2:48:13 PM DOES NOT GET CHANGED
    1/4/2019 2:38:13 PM DOES CHANGE

    I should add - if i change the dates to a number first (and often have to Text to columns to make them all change ) and then run the macro (either version) there is no problem and the dates do not get changed around

+ 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. [SOLVED] Change Date with Date Picker If Date Less Than 7 Days From Another Date
    By Macfool in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2016, 09:10 AM
  2. If range value change, active cell equal date and time of change.
    By kmakjop in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2015, 02:43 PM
  3. Replies: 4
    Last Post: 11-26-2014, 09:22 PM
  4. Change the content of a cell based on change the current date
    By aimanraya in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-14-2014, 07:07 AM
  5. Cell change --> date change macro
    By K3mp3r in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-07-2014, 05:31 AM
  6. Replies: 5
    Last Post: 05-17-2006, 03:00 AM
  7. [SOLVED] how do i make a date change automatically if i change one before .
    By dpl7579 in forum Excel General
    Replies: 1
    Last Post: 01-11-2005, 06:06 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