问题描述
For Each rcell In rg
If rcell.Value <> rcell.Offset(-1, 0).Value Then
If rcell.Offset(-1, 0).Interior.ColorIndex = 19 Then
Rows(rcell.row).Interior.ColorIndex = 2
Else
'rcell.Interior.ColorIndex = 19
Rows(rcell.row).Interior.ColorIndex = 19
End If
Else
Rows(rcell.row).Interior.ColorIndex = rcell.Offset(-1, 0).Interior.ColorIndex
End If
Next rcell
我需要逻辑来处理数组的颜色设置,例如
777,777,777,888,888,999,999,999,999
上面的逻辑在excel vba中,如果有人可以提供帮助,我表示感谢.我已经在下面尝试过,但是它并没有按照我想要的方式工作.
I need the logic how to handle color setting for an array e.g.
777,777,777,888,888,999,999,999,999
The logic above is in excel vba, if someone can help, I appreciate. I had tried below, but it did not work the way I want it.
for(i=0;i<arraysize;i++)>
{
if (array[i] == array[i-1])
setColor(YELLOW);
else
setColor(White);
}
我喜欢像奇数和偶数一样做颜色,
如果777,77,777,则设置为黄色
如果888,888,则设置为白色
如果999,999,999,则设置为黄色
等...
提前谢谢.
[edit]已添加代码块-OriginalGriff [/edit]
I like to do the color like odd and even,
if 777,77,777 then set yellow
if 888,888 then set white
if 999,999,999 then set yellow
etc...
Thanks in advance.
[edit]Code block added - OriginalGriff[/edit]
推荐答案
if (array[i] == array[i-1])
这将导致您第一次通过i == 0
遇到问题.您的循环应以i = 1
开始.但是,如果要基于奇数或偶数值进行确定,则应执行以下操作:
This will cause you problems first time through when i == 0
. Your loop should start with i = 1
. However if you want to make the determination based on odd or even values then you should do the following:
for(i = 0; i > arraysize; i++)
{
if (array[i] & 1)
setColor(YELLOW); // odd value
else
setColor(White); // even value
}
int i=1;
for(j=0;j<arraysize;j++)
{
if (array[j] == array[j+1])
{
if (i%2 !=0)
setColor(YELLOW);
else
setColor(White);
}
else
{
if (i%2 !=0)
setColor(YELLOW);
else
setColor(WHITE)
i++;
}
}
这篇关于在将几行excel vba代码转换为c ++时需要帮助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!