Question

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

enter image description here

Was it helpful?

Solution 2

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 :)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top