ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel2007 crashes while setting chart formatting (https://www.excelbanter.com/excel-programming/416832-excel2007-crashes-while-setting-chart-formatting.html)

Hakyab

Excel2007 crashes while setting chart formatting
 
All I am trying is to set the color of the graph line:

With Charts("Ranks")
For i = 1 To 18
CurT = GrData.Cells(i, 1)
.SeriesCollection(i).Border.ColorIndex = TakimR.Cells(CurT, 5)
Next i
End With

Excel crashes when the fourth line above executes (when file is recovered
the line color for the first series is set correctly, so I guess it crashes
after executing). Same thing happens when I try to set Border.Weight as
well. On the other hand, Border.Color can be set without any crashes.

I tried including .clearformats before the problem line, but did not help.

Can anyone help me with this problem? I can at least do the color part if
some one could tell me how to convert ColorIndex to a color number.

Thanks,
Hakan


Jon Peltier

Excel2007 crashes while setting chart formatting
 
I crashed Excel also. Then I rearranged your code slightly, and used an
intermediate variable for the color index retrieved from the sheet. This
code didn't crash, and colored the lines according to the default Excel 2003
palette:

Sub ColorLines()
Dim CurT As Long
Dim GrData As Worksheet
Dim TakimR As Worksheet
Dim i As Long
Dim ColIdx As Long

Set GrData = Worksheets(1)
Set TakimR = Worksheets(1)

With Charts("Ranks")
For i = 1 To 18
CurT = GrData.Cells(i, 1).Value
ColIdx = TakimR.Cells(CurT, 5).Value
.SeriesCollection(i).Border.ColorIndex = ColIdx
Next i
End With

End Sub


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Hakyab" wrote in message
...
All I am trying is to set the color of the graph line:

With Charts("Ranks")
For i = 1 To 18
CurT = GrData.Cells(i, 1)
.SeriesCollection(i).Border.ColorIndex = TakimR.Cells(CurT, 5)
Next i
End With

Excel crashes when the fourth line above executes (when file is recovered
the line color for the first series is set correctly, so I guess it
crashes
after executing). Same thing happens when I try to set Border.Weight as
well. On the other hand, Border.Color can be set without any crashes.

I tried including .clearformats before the problem line, but did not help.

Can anyone help me with this problem? I can at least do the color part if
some one could tell me how to convert ColorIndex to a color number.

Thanks,
Hakan




Hakyab

Excel2007 crashes while setting chart formatting
 
Thanks again Jon. Weird thing is, it worked when I appended .value at the
end, i.e.

.SeriesCollection(i).Border.ColorIndex = TakimR.Cells(CurT, 5).value

without intermediate variable. Hope someone from Microsoft is reading this.

Best,

Hakan

"Jon Peltier" wrote:

I crashed Excel also. Then I rearranged your code slightly, and used an
intermediate variable for the color index retrieved from the sheet. This
code didn't crash, and colored the lines according to the default Excel 2003
palette:

Sub ColorLines()
Dim CurT As Long
Dim GrData As Worksheet
Dim TakimR As Worksheet
Dim i As Long
Dim ColIdx As Long

Set GrData = Worksheets(1)
Set TakimR = Worksheets(1)

With Charts("Ranks")
For i = 1 To 18
CurT = GrData.Cells(i, 1).Value
ColIdx = TakimR.Cells(CurT, 5).Value
.SeriesCollection(i).Border.ColorIndex = ColIdx
Next i
End With

End Sub


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Hakyab" wrote in message
...
All I am trying is to set the color of the graph line:

With Charts("Ranks")
For i = 1 To 18
CurT = GrData.Cells(i, 1)
.SeriesCollection(i).Border.ColorIndex = TakimR.Cells(CurT, 5)
Next i
End With

Excel crashes when the fourth line above executes (when file is recovered
the line color for the first series is set correctly, so I guess it
crashes
after executing). Same thing happens when I try to set Border.Weight as
well. On the other hand, Border.Color can be set without any crashes.

I tried including .clearformats before the problem line, but did not help.

Can anyone help me with this problem? I can at least do the color part if
some one could tell me how to convert ColorIndex to a color number.

Thanks,
Hakan





Jon Peltier

Excel2007 crashes while setting chart formatting
 
You should always use .Value at the end. It's bad practice to rely on the
default properties. Not that they're likely to change them, but weird stuff
happens whenever there's an upgrade.

You should also declare all of your variables, and reference objects fully,
like ActiveWorkbook.Worksheets("Sheet1") instead of just
Worksheets("Sheet1").

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Hakyab" wrote in message
...
Thanks again Jon. Weird thing is, it worked when I appended .value at the
end, i.e.

.SeriesCollection(i).Border.ColorIndex = TakimR.Cells(CurT, 5).value

without intermediate variable. Hope someone from Microsoft is reading
this.

Best,

Hakan

"Jon Peltier" wrote:

I crashed Excel also. Then I rearranged your code slightly, and used an
intermediate variable for the color index retrieved from the sheet. This
code didn't crash, and colored the lines according to the default Excel
2003
palette:

Sub ColorLines()
Dim CurT As Long
Dim GrData As Worksheet
Dim TakimR As Worksheet
Dim i As Long
Dim ColIdx As Long

Set GrData = Worksheets(1)
Set TakimR = Worksheets(1)

With Charts("Ranks")
For i = 1 To 18
CurT = GrData.Cells(i, 1).Value
ColIdx = TakimR.Cells(CurT, 5).Value
.SeriesCollection(i).Border.ColorIndex = ColIdx
Next i
End With

End Sub


- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Hakyab" wrote in message
...
All I am trying is to set the color of the graph line:

With Charts("Ranks")
For i = 1 To 18
CurT = GrData.Cells(i, 1)
.SeriesCollection(i).Border.ColorIndex = TakimR.Cells(CurT, 5)
Next i
End With

Excel crashes when the fourth line above executes (when file is
recovered
the line color for the first series is set correctly, so I guess it
crashes
after executing). Same thing happens when I try to set Border.Weight
as
well. On the other hand, Border.Color can be set without any crashes.

I tried including .clearformats before the problem line, but did not
help.

Can anyone help me with this problem? I can at least do the color part
if
some one could tell me how to convert ColorIndex to a color number.

Thanks,
Hakan








All times are GMT +1. The time now is 02:18 AM.

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