Forum Discussion
ONG ZHEN YANG RP
May 18, 2018Brass Contributor
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 =...
- 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 
ONG ZHEN YANG RP
May 18, 2018Brass Contributor
Haytham Amairah I actually made a new code, can you help me check it
Sub chessboard()
Dim Col, Row As Integer
Col = 1
Do While Col < 21
Row = 1
Do While Row < 21
Dim i As Integer
i = Col Mod 2 = 1
Dim j As Integer
j = Col Mod 2 <> 0
Dim RowRange, ColRange
RowRange = 20
ColRange = 20
Select Case Cells(Row, Col)
Case i
Cells(Row, Col).Interior.Color = vbWhite
Case j
Cells(Row, Col).Interior.Color = vbYellow
End Select
Col = Col + 1
Loop
Row = Row + 1
Loop
End Sub
Haytham Amairah
May 18, 2018Silver Contributor
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
- ONG ZHEN YANG RPMay 18, 2018Brass Contributor
Haytham Amairah Alright, thank you very much! :)