更改 MS Excel 2003 的背景

发布于 2024-11-11 14:10:30 字数 1116 浏览 4 评论 0原文

我是 c# 编码员,到目前为止,这是我所知道的表达我想要的内容的最佳方式。 我正在考虑在 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";
    }

}

我不确定这是否可行。或者如果有任何其他与我想做的事情相当的方法,你能帮助我吗? :) 谢谢!

I'm a c# coder and so far this is the best way I know to express what I wanted.
I am thinking of doing this code below on a microsoft excel 2003 worksheet.
Could this be possible?

1st step

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

2nd step

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

So the code I wanted to do on MSExcel 2003 would look like this

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

}

I'm not sure if this is possible. Or if there are any other ways equivalent on what I wanted to do, can you please help me. :) Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一指流沙 2024-11-18 14:10:30

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

If all you want to do is change the color of a cell based on its value, just use conditional formatting in excel, no need for any programming.

ˇ宁静的妩媚 2024-11-18 14:10:30
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

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

You can find the list of colors here

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文