ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Nexted For Statements don't execute fully (https://www.excelbanter.com/excel-programming/404123-nexted-statements-dont-execute-fully.html)

EJKorvette[_2_]

Nexted For Statements don't execute fully
 
I am trying to use the following code to display all cell colors with all
border colors.
For some reason that I can't understand though, execution always stops
before the nested for statements can finish. The most it will get through is
i = 55 and j = 42.

Sub color()
Dim i, j As Integer
i = 0
j = 0

Worksheets("sheet4").Visible = True
For i = 1 To 56
For j = 1 To 56
Range("a3") = i
Range("a6") = j

Worksheets("Sheet4").Cells(i, j).Interior.ColorIndex = i
Worksheets("Sheet4").Cells(i, j).Borders.ColorIndex = j

Next j
Next i

End Sub

Is there some kind of internal limit Excel has to how many color
combinations can exist on one worksheet? I know that there are a maximum of
4000 styles, but there are only 55 * 42 = 2310 combinations here, not styles.
Why won't the program execute all the way?


Don Guillett

Nexted For Statements don't execute fully
 

IF? I did this, I would have done it differently but it ran as written.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"EJKorvette" wrote in message
...
I am trying to use the following code to display all cell colors with all
border colors.
For some reason that I can't understand though, execution always stops
before the nested for statements can finish. The most it will get through
is
i = 55 and j = 42.

Sub color()
Dim i, j As Integer
i = 0
j = 0

Worksheets("sheet4").Visible = True
For i = 1 To 56
For j = 1 To 56
Range("a3") = i
Range("a6") = j

Worksheets("Sheet4").Cells(i, j).Interior.ColorIndex = i
Worksheets("Sheet4").Cells(i, j).Borders.ColorIndex = j

Next j
Next i

End Sub

Is there some kind of internal limit Excel has to how many color
combinations can exist on one worksheet? I know that there are a maximum
of
4000 styles, but there are only 55 * 42 = 2310 combinations here, not
styles.
Why won't the program execute all the way?




All times are GMT +1. The time now is 11:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com