在将几行excel vba代码转换为c ++时需要帮助吗? [英] Need help on convert few lines of excel vba code to c++?

查看:202
本文介绍了在将几行excel vba代码转换为c ++时需要帮助吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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
}


Richard,谢谢.

777,777,777,888,888,999,999,999,999,111

很抱歉在奇数和偶数之间出现混淆,我的意思是黄色和白色是交替的颜色.
如果是7777,777,777,那么
setColor(黄色)

如果是888,888,那么
setColor(white)

如果999,999,999,999则
setColor(yellow)//

如果是111,那么
setColor(white)

那些具有相同值的数组元素将设置相同的颜色.对于奇数甚至偶数,我可以使用MOD(%).再次感谢.
Richard, Thanks.

777,777,777,888,888,999,999,999,999,111

Sorry for the confusion aout odd&even, what I meant is that the color yellow and white are alternate.
if 7777,777,777 then
setColor(yellow)

if 888,888 then
setColor(white)

if 999,999,999,999 then
setColor(yellow) //

if 111 then
setColor(white)

Those array elements has same value will set same color. For odd and even I can use MOD (%). Thanks again.


感谢您的帮助和观看.
我终于明白了.这不是一个很好的方法,但它确实起作用.我已经测试过了.

Thanks for helping and viewing.
I am finally figured it out. It is not a good one, but it worked. I had tested.

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 ++时需要帮助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆