Using VBA in Excel 2010 to create Charts

Warda

New Member
Joined
Apr 1, 2015
Messages
8
HI

I am working on huge amount of Data and I need to create charts for more than 277 sheets each with over 10000 rows and 92 Columns.

The Data are measurmnets for some force over the year and these measurments are recorded in a table for 365 days and for each day there are 24 records a record for ecah hour.

Some titles of the Columns are Titeld as Following : MM=Month , DD=Day , HH=Hour , Force=WG.

What I want is a VBA code to create a chart with HH on x-axis and WG on Y-axis I tried a code from this forum it did work but the plots are overlapping so on x-axis it is showing just from 0-24 and the ploting. I wnat the x-axis to be continous 0-24 then again 0-24 and so on.

Please if you can help me with that?

The table below shows a sample of what I mean.


MM DD HH WG
1116,1
1129,2
11310,2
1149,7
11510,8
11610,2
11710,2
11810,2
1199,7
11109,7
111110,2
11128,7
111310,8
11149,2
11158,2
11167,7
11176,6
11187,2
11197,2
11205,6
11215,6
11225,6
11237,2
11247,2
1218,2
1228,2
1239,2
1249,2
1259,2
1269,7
12712,3

<tbody>
</tbody>

the code I did use is
Private Sub CommandButton3_Click()


Application.ScreenUpdating = False
Dim LastRow As Long
Dim xTitle As Range
Dim xData As Range
Dim yColumn As Long
Dim yTitle As Range
Dim yData As Range
Dim GraphRange As Range


'Find last row with Data
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.count, "A").End(xlUp).Row


'Set x-axis title and Data
Set xTitle = Range("C1")
Set xData = Range("C2:C" & LastRow)


'Find Temperature, set y-axis title
With Rows(1)
Set yTitle = .Find("WG", LookIn:=xlValues)
yColumn = yTitle.Column
End With


'set y-axis data
Set yData = Range(Cells(2, yColumn), Cells(LastRow, yColumn))


'set total graph range
Set GraphRange = Union(xTitle, xData, yTitle, yData)


'create chart
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=GraphRange
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.SetElement (msoElementLegendNone)
ActiveChart.ChartTitle.Text = "Chart Title Here"
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
Selection.Caption = xTitle
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleRotated)
Selection.Caption = yTitle

Application.ScreenUpdating = True


End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
xaxis as valuesyaxisxaxis as textyaxis
115115
311311
512512
114114
3939
510510
116116
314314
513513
by converting the x axis values to text
I made a bar chart where the x axis was
1,3,5,1,3,5,1,3,5

<colgroup><col><col span="2"><col><col span="2"></colgroup><tbody>
</tbody>
 
Upvote 0
Hi oldbrewer

Do you mean I need to change cells form to text for the whole table or just for the x-axis valuse I need?

I tried it but it didn't work.

thanks in advanced
 
Last edited:
Upvote 0
as my post says, I converted x axis labels to text, the Y values have to be values, my bar chart was fine.

do what i did make a new spreadsheet with simple dummy data to test ogut the methodology........
 
Upvote 0
number of charactersposition of commacharacters before commacharacters after commapre decimal point numberpost decimal point numberactual decimal numberfinal number
17,243211720.217.2
4,567521345670.5674.567
6543454,54547138756543454545470.545476543454.545
using LEN, SEARCH, LEFT and MID the text number is converted to a proper number to enable it to be charted

<colgroup><col><col><col><col><col><col><col span="3"><col><col></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top