Results 1 to 4 of 4

Thread: Help with a Macro to insert a column of a fairly complicated Date/Time function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    451
    Location
    I tried ActiveCell.Formula and that worked.

    It is not necessary to actually Select anything. I was able to set formula in each cell with this:
    Sub AGS_Date()
    Dim r As Integer
    r = Range("A" & Rows.Count).End(xlUp).Row
    Columns("A:A").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A1").Value = "Time"
    Range("A2:A" & r).Formula = "=DATE(LEFT(B2,4),MID(B2,5,2),MID(B2,7,2)) + TIME(MID(B2,10,2), MID(B2,12,2), MID(B2,14,2))+MID(B2,16,4)/86400"
    Range("A2:A" & r).NumberFormat = "0.0000000000"
    'Range("A2:A" & r).NumberFormat = "yyyy-mm-dd hh:mm:ss AM/PM"
    End Sub
    Why replace formula with values? But if you must:
    Columns("A").Copy
    Columns("A").PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Range("A1").Select
    Last edited by June7; 10-06-2023 at 03:07 PM.
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Posting Permissions

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