Consulting

Results 1 to 3 of 3

Thread: Date Time copy paste not including time

  1. #1
    VBAX Regular
    Joined
    Apr 2008
    Posts
    97
    Location

    Date Time copy paste not including time

    OK, this is probably a simple fix but I have been banging my head on this one for a while now.

    I have a CSV file that I import into a sheet and run a text to columns process to slit it up. One column has date and one has time and all the data appears to be there.
    Date column B = 41289
    Time Column C = 0.676793981481482

    When I enter a formula to combine them in column D like =B1+C1 I get the proper value of 41289.676794

    The problem I have is when I copy the entire column D and paste as values in column E in VBA it always drops the time from the number (EI 41289.0)

    [VBA]
    Range("E1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks_:=False, Transpose:=False
    [/VBA]

    What I am doing wrong here? I have tried number formating, paste as valueandnumberformats, etc.
    Works fine manually but in code it always drops the time?

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Works ok for me. Make a short example file and attach for us to troubleshoot.

    [VBA] Range("D1").Copy
    Range("E1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False[/VBA]

  3. #3
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    I believe that should work too.

    But...
    You could also try such solution.
    Select range to copy and run this macro:[vba]Sub AAA()
    Dim vArr As Variant

    If TypeName(Selection) <> "Range" Then Exit Sub

    vArr = Selection

    If Selection.Count = 1 Then
    Range("E1") = vArr
    Else
    Range("E1").Resize(UBound(vArr), UBound(vArr, 2)).Value = vArr
    End If

    End Sub[/vba]

    Artik

Posting Permissions

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