更改MS Excel 2003的背景

我是ac#编码器,到目前为止,这是我知道expression我想要的最好方式。 我正在考虑在Microsoft Excel 2003工作表上执行下面的代码。 这可能吗?

第一步

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"; } } 

我不确定这是否可能。 或者如果有什么其他的方式等同于我想要做的,你能帮我一下吗? :) 谢谢!

 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 

你可以在这里find颜色列表

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

如果你所要做的只是基于它的值来改变单元格的颜色,那么只需在excel中使用条件格式,而不需要任何编程。