Consulting

Results 1 to 4 of 4

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

  1. #1
    VBAX Newbie
    Joined
    Oct 2023
    Posts
    2
    Location

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

    I am new to this Forum, and it appears I'm NOT doing this correctly!

    I created a long post, containing explanation, sample data, and Macro code I am trying to debug.
    When I Submit, the post is denied, with the only explanation that new posts my be denied due to excessive URLs (I had none), or "prohibited words", which I sincerely hope I wasn't using (not that I know what those might be!)

    So far, this passes Preview, so hopefully acceptable.
    I'll try attaching a Word doc where I saved the text!

    Thanks for any help!
    Dave

    Attached Files Attached Files

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    337
    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.

  3. #3
    VBAX Newbie
    Joined
    Oct 2023
    Posts
    2
    Location
    Fantastic! Thank you.
    Only fix-up was to use "Dim r As Long"

    I forget how much can be done en masse, instead of iteratively.Dave

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Welcome to VBAX Dave. Once you've been posting to the forum a few times, the rules set up by the Admin will ease as to what can be posted.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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