Forum Discussion

ONG ZHEN YANG RP's avatar
ONG ZHEN YANG RP
Brass Contributor
May 18, 2018
Solved

Needs Help with Some Editing of A Code

Help me edit this code to achieve this end result. As much as possible, please keep the format the same for "select case" and "Loop"  Sub QuestionFive() Dim r, c As Integer Do While r < 20 r =...
  • Haytham Amairah's avatar
    Haytham Amairah
    May 18, 2018

    Hi ONG,

     

    Using SELECT CASE statement for this purpose is really tricky, but finally, I figure it out!

     

    This is the code:

    Sub Chessboard()
            
        Dim r As Integer
        Dim c As Integer
        r = 1
        c = 1

        Do While r <= 20 And c <= 20
        
        Dim ir As Boolean
        ir = r Mod 2 = 0
        
        Dim ic As Boolean
        ic = c Mod 2 = 0
        
        Dim i As Boolean
        i = ir = ic
        
        Select Case i
            Case True
                Cells(r, c).Interior.Color = vbYellow
            Case False
                Cells(r, c).Interior.Color = vbWhite
        End Select
        
        r = r + 1
            
        If r > 20 Then
           r = 1
           c = c + 1
        ElseIf c > 20 Then
           Exit Sub
        End If
        
        Loop
        
    End Sub

     

Resources