我是通过模板输入数据的
在模板中设置好了
但是程序写入发觉没变化
那如何在程序中设置呢
比如我要 设置某一行的颜色(灰色)
某一列为"#00.00"(自动保留两位有效数字的数值类型)

解决方案 »

  1.   

    例如设置A1-M1
    Excelworksheet.Range("A1:M1").ColorIndex=16
    Excelworksheet.Range("A1:M1").NumberFormat=""#00.00"
      

  2.   


    Excell的VBA编程很多都可以用录制宏的方式得到代码,不一定要来求助的。当然用录制宏的方式得到的代码有很多是垃圾代码,我们还要做一定的剪辑。
      

  3.   

    ---1---
    Example
    This example sets the formula, column width, and number format for cell B5 on Sheet1 in Spreadsheet1.Sub SetFormula()
        Dim rngRandomNum
        
        ' Set a variable to cell B5 on Sheet1.
        Set rngRandomNum = Spreadsheet1.Worksheets("Sheet1").Range("B5")
        
        ' Insert a formula into cell B5.
        rngRandomNum.Formula = "=5*RAND()"
        
        ' Set the number format for cell B5.
        rngRandomNum.NumberFormat = "#.###"
        
        ' Autofit column B.
        rngRandomNum.Columns.AutoFitEnd Sub
    ---2---
    Example
    These examples set the number format for cell A17, row one, and column C (respectively) on Sheet1.Worksheets("Sheet1").Range("A17").NumberFormat = "General"
    Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
    Worksheets("Sheet1").Columns("C").NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
      

  4.   

    Columns("A:B").Select
        With Selection.Interior
            .ColorIndex = 15
            .Pattern = xlSolid
        End With
        Selection.NumberFormatLocal = "0.00_ "
        Range("D2").Select
      

  5.   

    兄弟们,似乎还是不行啊
    还是一样啊
    虽然excel的单元格式变了,但是里面的数的格式还是不变化啊
    但是剪切出来再复制进去就变了。
      

  6.   

    谢谢大家
    我最后只好用formatnumber函数解决了
    下午结贴