Question : VBA Interior ColorIndex Excel

Hi, I have the following VBA code as part of a routine to insert x number of worksheets which can vary from 3 weeks to 40 plus weeks. Each worksheet is renamed Week 1 through to Week X depending on the number of weeks a project has to run.  The routine then changes the default tab and interior colors  of each worksheet to one of the color pastel colors starting at color index number 35.  Ideally what I would like to do is use only 4 colors, repeating every 4th weeks of the project, these being 35,36, 37 and 38.  Can anyone please provide the code I would need to add to achieve this.  I am assuming it will be some type of loop within this statement.  Regards JH
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
For i = 1 To Sheets.Count
    If Left(Sheets(i).Name, 4) = "Week" Then
    With Sheets(i)
    .Name = "Week " & i
    .Tab.ColorIndex = i + 34
    .Cells.Interior.ColorIndex = i + 34
    .Range("f7:G7,f9:g9,f11:g11,f13:g13,f16:g16,p5:s16,g22:g34,g37:g39,g47:g62,g42,l7,l9,l11,l13,l16").Interior.ColorIndex = 2
    End With
    End If
Next

Answer : VBA Interior ColorIndex Excel

Sorry...please change the 40 for 39 on the code, like this.

jppinto
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Dim color as Integer 
color = 35 
For i = 1 To Sheets.Count  
    If Left(Sheets(i).Name, 4) = "Week" Then  
    With Sheets(i)  
    .Name = "Week " & i  
    .Tab.ColorIndex = color  
    .Cells.Interior.ColorIndex = color 
    .Range("f7:G7,f9:g9,f11:g11,f13:g13,f16:g16,p5:s16,g22:g34,g37:g39,g47:g62,g42,l7,l9,l11,l13,l16").Interior.ColorIndex = 2  
    End With  
    End If  
    color = color +1 
    If color = 39 Then  
       color = 35 
    End If 
Next
Random Solutions  
 
programming4us programming4us