I'd like to know how to "apply" cell formatting to a cell when we don't write manually.
I have a vb.net application which enter the date and time to a cell in excel. The cells are formatted to display the date only as 16/04/2013.
When the application enter the date, excel displays it as a string so with the time. But if I double click to edit the cell then confirm without changing anything it formats the cell right.
Here are the screens
The last 5 are entered by the application.
I edited the n°66 then confirmed by enter and it is how I want it
Thank you
EDIT: Here is the code I use
Dim day As Date
oExcel.ScreenUpdating = False
oExcel.cells(6, 3).Select()
While oExcel.ActiveCell.Value <> Nothing
oExcel.ActiveCell.OffSet(1, 0).Select()
End While
oExcel.ScreenUpdating = True
day = DateValue(Now)
oExcel.ActiveCell.Value = day & " " & TimeOfDay
oExcel.ActiveCell.Offset(0, 1).Value = timeOutput
EDIT2: Found a workaround
I found a way to convert the string to a number in excel here is the code:
Dim writeThis As String = day & " " & TimeOfDay
With oExcel.ActiveCell
.OffSet(0, 10).Value = writeThis
.Formula = "=" & oExcel.ActiveCell.OffSet(0, 10).Address & "+0"
.Formula = oExcel.ActiveCell.Value
.OffSet(0, 10).Value = Nothing
.Offset(0, 1).Value = timeOutput
End With
I'm not sure it's the best way to do it but it works so i'm happy with it. Thank you Siddharth for all your help :)