PDA

View Full Version : Date Time copy paste not including time



slang
02-20-2013, 08:50 AM
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)


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


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?
:banghead: :dunno

Kenneth Hobs
02-20-2013, 09:47 AM
Works ok for me. Make a short example file and attach for us to troubleshoot.

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

Artik
02-20-2013, 06:23 PM
I believe that should work too.

But...
You could also try such solution.
Select range to copy and run this macro: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

Artik