VBA example - Excel 2007: VBA color pattern 9


VBA code to colors pattern 9

In this VBA example code, you will learn to generate a colored pattern as shown below. It is a combination of two half-matrixes of color patterns--lower-left and upper-left color matrixes.

To run this example VBA code, you will need a Form, and a CommandButton.


VBA MS Excel: VBA loop example code to generate color pattern-pattern 9

VBA code for this example:


Option Explicit Private Sub CommandButton1_Click()
 
Dim i, j, l, m As Integer
  l = 6 m = 6  
 
For l = 1 To 6   
 
For m = 1 To 6
   
        
If (l = m) Then
     
          
Cells(l, m).Interior.Color = RGB(200, 10, 10)
       
        
ElseIf (l > m) Then
    
           
Cells(l, m).Interior.Color = RGB(10, 10, 200)
                   
        
ElseIf (l < m) Then
         'No filling                     
        
End If
         
  
Next

  Next  
 For i = l To 13
    For j = 6 To 1 Step -1      
      
If (i + j = 14) Then
       
        
Cells(i, j).Interior.Color = RGB(200, 10, 10)
            
      
ElseIf (i + j > 14) Then
      'No filling              
      
ElseIf (i + j < 14) Then
       
        
Cells(i, j).Interior.Color = RGB(10, 10, 200)
                 
     
End If
           
 
Next

 Next  
End Sub

Comments

Comments

Name:
Comment:
Enter the text:
CAPTCHA image




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.