How to change Format of a Cell to Text using VBA

前端 未结 4 1342
一整个雨季
一整个雨季 2020-12-03 04:34

I have a "duration" column in an Excel sheet. Its cell format always changes — I want convert the duration from minutes to seconds, but because of the cell formatt

相关标签:
4条回答
  • 2020-12-03 04:37

    for large numbers that display with scientific notation set format to just '#'

    0 讨论(0)
  • 2020-12-03 04:38

    To answer your direct question, it is:

    Range("A1").NumberFormat = "@"
    

    Or

    Cells(1,1).NumberFormat = "@"
    

    However, I suggest making changing the format to what you actually want displayed. This allows you to retain the data type in the cell and easily use cell formulas to manipulate the data.

    0 讨论(0)
  • 2020-12-03 04:41

    Well this should change your format to text.

    Worksheets("Sheetname").Activate
    Worksheets("SheetName").Columns(1).Select 'or Worksheets("SheetName").Range("A:A").Select
    Selection.NumberFormat = "@"
    
    0 讨论(0)
  • 2020-12-03 04:42

    One point: you have to set NumberFormat property BEFORE loading the value into the cell. I had a nine digit number that still displayed as 9.14E+08 when the NumberFormat was set after the cell was loaded. Setting the property before loading the value made the number appear as I wanted, as straight text.

    OR:

    Could you try an autofit first:

    Excel_Obj.Columns("A:V").EntireColumn.AutoFit
    
    0 讨论(0)
提交回复
热议问题