+ Reply to Thread
Results 1 to 6 of 6

Macro filling UK Date that is a value as a US date in column with same format as source

Hybrid View

  1. #1
    Registered User
    Join Date
    08-06-2012
    Location
    Hereford
    MS-Off Ver
    Excel 2010
    Posts
    11

    Macro filling UK Date that is a value as a US date in column with same format as source

    I have a file in named range 'caldata3' with a date saved as a value with the format
    Date
    14/03/2012
    English (United Kingdom)
    If the date in question is 07/01/2021 my macro fills this data to another file but it appears as a US date of 01/07/2021. The target column has the same format as above.
    Here is my code.

    Sub logsievecalibration()
    '
    Dim ThisWorkBook As String
    Dim SheetName As String
    Dim MyRanges(13) As String
    Dim EmptyRow As Long
    Dim a As Integer 'to cyle through ranges
    
    
    ' Unprotect sheet to allow macro to function
     Call UnProtectSheets
        
    Worksheets("Sieve Details & Results").Activate
     
    ThisWorkBook = ActiveWorkbook.Name
    SheetName = ActiveSheet.Name
     
    'Named Ranges with sheets specified as from more than one sheet
    
    MyRanges(1) = "caldata1" 'Certificate Type - col B
    MyRanges(2) = "caldata2" 'Certificate Number - col C
    MyRanges(3) = "caldata3" 'Calibration Date - col D
    MyRanges(4) = "caldata4" 'Customer Account Number - col D
    MyRanges(5) = "caldata5" 'Customer Name - col E
    MyRanges(6) = "caldata6" 'Col5 from Opera records should be Town - col F
    MyRanges(7) = "caldata7" 'Postcode column from Opera records should be Postcode - col G
    MyRanges(8) = "caldata8" 'Standard - col H
    MyRanges(9) = "caldata9" 'Diameter - col I
    MyRanges(10) = "caldata10" 'Aperture - col K
    MyRanges(11) = "caldata11" 'Unique Identifier - col L
    MyRanges(12) = "caldata12" 'Email Address - col L
    MyRanges(13) = "caldata13" 'Job Number - col M
    
    '   Assign values from range names to array
       MyRanges(1) = Range("caldata1").Value
       MyRanges(2) = Range("caldata2").Value2
       MyRanges(3) = Range("caldata3").Value
       MyRanges(4) = Range("caldata4").Value
       MyRanges(5) = Range("caldata5").Value
       MyRanges(6) = Range("caldata6").Value
       MyRanges(7) = Range("caldata7").Value
       MyRanges(8) = Range("caldata8").Value
       MyRanges(9) = Range("caldata9").Value
       MyRanges(10) = Range("caldata10").Value
       MyRanges(11) = Range("caldata11").Value
       MyRanges(12) = Range("caldata12").Value
       MyRanges(13) = Range("caldata13").Value
       
       
       
        Workbooks.Open filename:= _
            "S:\Calibrations\Ledgers\Sieve_Ledger_Latest.xls"
        Workbooks("Sieve_Ledger_Latest.xls").Activate
            
    With Workbooks("Sieve_Ledger_Latest.xls")
        .Sheets("Calibrations").Activate
         
        With ActiveSheet
             
             'find empty row
            EmptyRow = 0
            Do
                EmptyRow = EmptyRow + 1
            Loop Until IsEmpty(.Cells(EmptyRow, 1))
            
             .Cells(EmptyRow, 1) = Date
            
             'fill in other columns from named ranges
                     
            For a = 1 To UBound(MyRanges)
             .Cells(EmptyRow, a + 1) = MyRanges(a)
            Next a
            
        End With
         
        
         'save and close workbook
        .Save
        .Close
    End With
    I posted this query in the Microsoft forum but the only suggestion was;
        'Save today's date as value
        Range("caldata3") =  Format(Date, "dd/mm/yyyy")
    This is no good as it changes the date to the current one and I need to keep the original date.

    I am stumped and would be most grateful for some help with this, thanks.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Macro filling UK Date that is a value as a US date in column with same format as sourc

    This is a guess, but give it a shot...

    MyRanges(3) = DateValue(Range("caldata3").Value)
    The DateValue function converts a Text-Date into a Serial-Date using your computer's system date setting e.g. English (United Kingdom) d/m/yyyy
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    08-06-2012
    Location
    Hereford
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Macro filling UK Date that is a value as a US date in column with same format as sourc

    Quote Originally Posted by AlphaFrog View Post
    This is a guess, but give it a shot...

    MyRanges(3) = DateValue(Range("caldata3").Value)
    The DateValue function converts a Text-Date into a Serial-Date using your computer's system date setting e.g. English (United Kingdom) d/m/yyyy
    Thanks for trying AlphaFrog.
    Unfortunately source date of 07/01/21 saved to the ledger as 01/07/21.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Macro filling UK Date that is a value as a US date in column with same format as sourc

    Don't define MyRanges as a String. Define it as Variant so you can put an actual date value in there.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    08-06-2012
    Location
    Hereford
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Macro filling UK Date that is a value as a US date in column with same format as sourc

    Quote Originally Posted by rorya View Post
    Don't define MyRanges as a String. Define it as Variant so you can put an actual date value in there.
    Thank you rorya. You have saved me losing sleep over the weekend.
    I like your dog too.
    Many many thanks

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Macro filling UK Date that is a value as a US date in column with same format as sourc

    Glad we could help.

+ 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. Update given date column in general format to date format in VBA
    By l3sushi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2016, 02:32 PM
  2. [SOLVED] I need help on Auto Filling the date across 31 worksheets in my format
    By PeterSCTS in forum Excel General
    Replies: 6
    Last Post: 05-07-2014, 06:27 PM
  3. [SOLVED] I need help in auto filling the date across 31 worksheets using my format
    By PeterSCTS in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-07-2014, 01:28 AM
  4. Macro to change date value from one date format to another date format
    By RG12 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2013, 04:51 AM
  5. [SOLVED] Macro to update pivot item (date format) in pivot table to latest date from data source.
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2012, 03:18 AM
  6. Column Range with date Format MM/DD/YYYY independate of sys date Format
    By gaursh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2011, 03:31 AM
  7. Filling Column with date
    By Bill in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-21-2005, 02:05 AM

Tags for this Thread

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