Home » excel » How to fix cell format as excel cell is losing format after executing macro

How to fix cell format as excel cell is losing format after executing macro

Posted by: admin April 23, 2020 Leave a comment

Questions:

Hi i am populating data into excel worksheet using DDE.Execute command from Oracle forms. Code is fine but when I am executing the below macro FORMAT_SECTION_TITLE_2 using DDE.Execute command it colors the line but also changes the Date to number and rather value of the cell appearing as a proper date it appears as 39234

Sub FORMAT_SECTION_TITLE_2()

    With Selection.Interior
        .ColorIndex = 7
        .Pattern = xlSolid
    End With
    Selection.Font.Bold = False
End Sub

I have also tried to change lots of things but no help. please suggest.

Thanks

Update 1:
Siddharth I added a new sub in the excel sheet as you mentioned and my sheet name is the same as you mentioned Sheet1

Sub formatColumn()
Sheets("Sheet1").Columns(1).NumberFormat = "dd-mmm-yy"
End Sub
How to&Answers:

Shax, as discovered after Two and half hours of chat, it appears to be an XY Problem 🙂

Like I mentioned above, the above code was not responsible for the formatting changes. The formatting was changed by another piece of code

Sub two_decimals()
    Selection.NumberFormat = "#,##0.00"
End Sub

The actual fault lies in the oracle code which was calling the two_decimals after the FORMAT_SECTION_TITLE_2 I am not too good with oracle but when debugging it we found this problem.

BTW: Thanks to you, I learned few things in oracle today!