更改MS Excel 2003的背景

本文关键字:背景 2003 Excel MS 更改 | 更新日期: 2023-09-27 17:58:15

我是一名c#程序员,到目前为止,这是我所知道的表达我想要的东西的最佳方式。我正在考虑在microsoftexcel2003工作表上做下面的代码。这可能吗?

第一步

if(CellA1 == "Sunday" || CellA1== "Saturday"){
    // code to set background color of 
    // CellB1 to CellF1 to background color red
}

第二步

// Execute this process from CellA1 until CellA10    
for(CellA1 up to CellA10){
    // do first step
}

所以我想在MSExcel 2003上做的代码看起来像这个

for(int CellCount = 1;CellCount<10;CellCount++){
    if("CellA"+CellCount.ToString() == "Sunday" || 
       "CellA"+CellCount.ToString() == "Sunday"){
        // set ["CellB"+CellCount.ToString()].CellBackgroundColor="#FF0000";
        // set ["CellC"+CellCount.ToString()].CellBackgroundColor="#FF0000";
        // set ["CellD"+CellCount.ToString()].CellBackgroundColor="#FF0000";
        // set ["CellE"+CellCount.ToString()].CellBackgroundColor="#FF0000";
        // set ["CellF"+CellCount.ToString()].CellBackgroundColor="#FF0000";
    }
}

我不确定这是否可能。或者,如果我想做的事情还有其他等效的方法,你能帮我吗?:)谢谢!

更改MS Excel 2003的背景

如果您只想根据单元格的值更改单元格的颜色,只需在excel中使用条件格式即可,无需任何编程。

Sub backcolor()
Range("a1:a10").Interior.ColorIndex = xlNone
For Each cell In Range("a1:a10")
    If cell.Value = "Sunday" Or cell.Value = "Saturday" Then
        cell.Interior.ColorIndex = 3
    End If
Next cell
End Sub

你可以在这里找到颜色列表

http://dmcritchie.mvps.org/excel/colors.htm