Code:
Sub insertformulas()
Dim wb As Workbook: Set wb = ActiveWorkbook
With ActiveWorkbook
Columns("G:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("g2").Formula = "=TEXT(E2,mm/dd/yy)&TEXT(F2,hh:mm:ss)"
Range("h2").Formula = "=TEXT(G2-G3,hh:mm:ss)"
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("H2:H60")
Range("H2:H60").Select
Range("G2").Select
Selection.AutoFill Destination:=Range("G2:G60")
Range("G2:G60").Select
End With
End Sub
1. insert 2 columns from column G
2. Insert a formula in both new columns (G&H)
3. Copy the formula down
What happens when I run it is columns e&f go from being dates and time format to number format
Ex. 6/27/2018 to 43278
Ex. 8:03:15 to .33559
Then cells G2 and H2 come up as #NAME (due to the change of columns e&f and the formula does not recognize the number format)
Columns G&H do not copy down.
What is causing the date/time format to change in columns e&f and how do I fix it?
Thanks in advance