Reputation: 3096
Why isn't 'ALT' (variable used to determine row colour) being updated (see pic)
Here is the code:
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
here is the code that goes in the 'background color' first column:
=Code.Stripe(true, "#E7E7E7", "Transparent")
second to N columns:
=Code.Stripe(False, "#E7E7E7", "Transparent")
n.b. you may need to open the image in another window to see the debug output - I'm showing the values of 'cnt' and 'alt' using getalt & getcnt
Upvotes: 1
Views: 2964
Reputation: 5815
Looks like you're making things too complicated. You can use RowNumber to achieve alternate background coloring, something like:
=IIF(RowNumber("YourDataset") Mod 2, "#E7E7E7", "Transparent")
Note that YourDataset can also be the scope if you're using grouping.
Upvotes: 3
Reputation: 3096
The BGcolor code needs to be this in the first column
=IIF(code.getcnt() Mod 2, "#E7E7E7", "Transparent") & Code.Stripe(TRUE, "", "")
and this in the 2nd..N columns
=IIF(code.getcnt() Mod 2, "#E7E7E7", "Transparent") & Code.Stripe(FALSE, "", "")
I'm sure the code can be tidied up :)
Upvotes: 1