VBA example - Excel 2007: color pattern 1


VBA code to generate color pattern 1

In this VBA code example, you play with different colors that can be applied to your Excel worksheet. In this VBA example code, you will learn to generate a colored pattern as shown below.
To run this example VBA code, you will need a Form, and a CommandButton.


VBA MS Excel: VBA example code to generate color pattern-pattern 1

VBA code for this example:


Option Explicit Private Sub CommandButton1_Click()    
Dim i, j As Integer
   
i = 5
   
j = 10
   
For i = 1 To 5
     
For j = 1 To 5
           
  
If (i = j) Then
               
     
Cells(i, j).Interior.Color = RGB(200, 10, 10) 'diagonal
                           
   ElseIf (i > j) Then
               
     
Cells(i, j).Interior.Color = RGB(10, 200, 10) 'lower left- side
                           
   ElseIf (i < j) Then
               
     
Cells(i, j).Interior.Color = RGB(10, 10, 200) 'upper-right side
                           
  
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.