1

为什么不更新“ALT”(用于确定行颜色的变量)(见图)

这是代码:

Private Alt As Boolean
Private cnt as integer
Function Stripe(ByVal NewRow As Boolean, ByVal OddColor as String, ByVal EvenColor as String) As String
    If NewRow Then 
Alt = Not Alt ' Trip the switch denoting a new row
cnt = cnt + 1
end if
    If Alt Then
        Return OddColor
    Else
        Return EvenColor
    End If
End Function

Function getalt () as boolean
return alt
end function    

function getcnt() as integer
return cnt
end function

这是“背景颜色”第一列中的代码:

=Code.Stripe(true, "#E7E7E7", "Transparent")

第二到N列:

=Code.Stripe(False, "#E7E7E7", "Transparent")

注意,您可能需要在另一个窗口中打开图像才能查看调试输出 - 我正在使用 getalt 和 getcnt 显示“cnt”和“alt”的值

在此处输入图像描述

4

2 回答 2

2

看起来你把事情弄得太复杂了。您可以使用RowNumber来实现备用背景颜色,例如:

=IIF(RowNumber("YourDataset") Mod 2, "#E7E7E7", "透明")

请注意,如果您使用分组,YourDataset 也可以是范围。

于 2012-03-22T15:14:33.990 回答
1

BGcolor 代码需要在第一列中

=IIF(code.getcnt() Mod 2, "#E7E7E7", "透明") & Code.Stripe(TRUE, "", "")

这在第 2..N 列

=IIF(code.getcnt() Mod 2, "#E7E7E7", "透明") & Code.Stripe(FALSE, "", "")

我确定代码可以整理:)

于 2012-03-22T10:05:57.960 回答