The objective is to first fill color in 1 row then leave a blank and then fill color in 2 row and then leave a blank and go on till I fill color in 5 rows. Moreover I want to color the first row in each block differently. So I have used If Else statment. I have already gone through the many queries but they all were sorted out by starting new line after Then but in my case this is not working. Please look into my code and suggest changes.
Option Explicit
Option Base 1
Sub colMultiRow()
'
' colMultiRow Macro
' This colours multiple row with red
'
'The function colours variable no. of rows in each iteration
Dim num(5) As Integer
Dim i As Integer
Dim a As Integer
For a = 1 To 5
num(a) = a
'MsgBox (a & Chr(10))
Next
Dim row As Integer
row = 1
Dim j As Integer
For i = 1 To 5
For j = 1 To i
Cells(row, 1).EntireRow.Select
If j = 1 Then
'For writing in the row
'For coloring the row
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 13882817
Else
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15983023
End With
End If
row = row + 1
Next
row = row + 1
Next
End Sub
Aucun commentaire:
Enregistrer un commentaire