ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel automation, change Category (X) Axis Labels, VB6 (https://www.excelbanter.com/excel-programming/437292-excel-automation-change-category-x-axis-labels-vb6.html)

Zico Damatsu

Excel automation, change Category (X) Axis Labels, VB6
 
Hello,
I put some data to excel sheet from Access DB through VB6. I can create charts but I can set the labels for the X axes. For example if I set data for charts as :
| A | B |
1 | 3 | 10 |
2 | 4 | 25 |
3 | 5 | 55 |

Excel Automaticaly set LAbels for X-axes as: 3,4,5, and Y Values as 10,25,55. Because Title and value columns are next to each other.
But in my case I want Y values as Column B1:B3 and X labels as E1:E3 which is not next to column B.
| A | B | C | D | E |
1 | X | 10 | X | X | 3 |
2 | X | 25 | X | X | 4 |
3 | X | 55 | X | X | 5 |
Manually this can be done by changing Category (X) Axis Labels on Excel Chart's Source Data options.

Is there any way to do that by programming.

I use this sample code .
----------------------------------------------
Dim new_chart As Chart
Set new_chart = Charts.Add()

With new_chart
.ChartType = xlLineMarkers
.HasLegend = False
.SetSourceData Source:=active_sheet.Range("B1:B3), PlotBy:=xlColumns
.Location Whe=xlLocationAsObject, Name:=active_sheet.Name
End With

active_sheet.Shapes(active_sheet.Shapes.Count).Top = 10
active_sheet.Shapes(active_sheet.Shapes.Count).Lef t = _
100
active_sheet.Shapes(active_sheet.Shapes.Count).Wid th = _
600
active_sheet.Shapes(active_sheet.Shapes.Count).Hei ght = _
400


ActiveChart.ChartArea.Select
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Monthly BSP Index"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, _
xlPrimary).AxisTitle.Characters.Text = "Month"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text _
= "Value"
End With



Submitted via EggHeadCafe - Software Developer Portal of Choice
Building Websites with DotNetNuke
http://www.eggheadcafe.com/tutorials...s-with-do.aspx

Gerald Haberl

Excel automation, change Category (X) Axis Labels, VB6
 
With new_chart
.........
.SeriesCollection(1).XValues=active_sheet.Range("E 1:E3")
End With

Gerald

<Zico Damatsu schrieb im Newsbeitrag
...
Hello,
I put some data to excel sheet from Access DB through VB6. I can create
charts but I can set the labels for the X axes. For example if I set data
for charts as :
| A | B |
1 | 3 | 10 |
2 | 4 | 25 |
3 | 5 | 55 |

Excel Automaticaly set LAbels for X-axes as: 3,4,5, and Y Values as
10,25,55. Because Title and value columns are next to each other.
But in my case I want Y values as Column B1:B3 and X labels as E1:E3 which
is not next to column B.
| A | B | C | D | E |
1 | X | 10 | X | X | 3 |
2 | X | 25 | X | X | 4 |
3 | X | 55 | X | X | 5 |
Manually this can be done by changing Category (X) Axis Labels on Excel
Chart's Source Data options.

Is there any way to do that by programming.

I use this sample code .
----------------------------------------------
Dim new_chart As Chart
Set new_chart = Charts.Add()

With new_chart
.ChartType = xlLineMarkers
.HasLegend = False
.SetSourceData Source:=active_sheet.Range("B1:B3), PlotBy:=xlColumns
.Location Whe=xlLocationAsObject, Name:=active_sheet.Name
End With

active_sheet.Shapes(active_sheet.Shapes.Count).Top = 10
active_sheet.Shapes(active_sheet.Shapes.Count).Lef t = _
100
active_sheet.Shapes(active_sheet.Shapes.Count).Wid th = _
600
active_sheet.Shapes(active_sheet.Shapes.Count).Hei ght = _
400


ActiveChart.ChartArea.Select
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Monthly BSP Index"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, _
xlPrimary).AxisTitle.Characters.Text = "Month"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text _
= "Value"
End With



Submitted via EggHeadCafe - Software Developer Portal of Choice
Building Websites with DotNetNuke
http://www.eggheadcafe.com/tutorials...s-with-do.aspx





All times are GMT +1. The time now is 03:20 AM.

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