Histogram with unknown column length data

scolty1985

Board Regular
Joined
Sep 16, 2009
Messages
88
Good afternoon all, I was hoping someone would be kind enough to help me with this wee problem.

Im trying to write a VBA program which will automatically create a histogram for me. I already have an example for plotting an XY scatter which im trying to modify but thus far with no success.

Issues:

1) Im not sure what the syntax is for creating a histogram

2) Im not sure how to use the existing example i have so it references an undisclosed number of rows in a column.

The existing code i have, written by someone here i believe, is as follows:

Code:
With Worksheets("Sheet3").ChartObject.Add _
    (Left:=200, Width:=400, Top:=250, Height:=225)
    .Chart.SetSourceData Source:=Worksheets("DataSheet").Range("H2:H6")
    .Chart.ChartType = xlXYScatterLines

I usually use the following:

Code:
LC = Range("A" & Rows.Count).End(xlUp).Row

To store the number of rows in a column. I dont know how i can use that in a range though, ie

...Range("H2: H(LC)").ch....

If someone could also comment on the correct syntax for a historgram so i can replace the line

Code:
Chart.ChartType = xlXYScatterLines

I would appreciate it.

Rgds

Scolty
 
I created a chart manually on sheet3 then ran this with another sheet selected and it renamed the chart

Code:
Sub test()
Worksheets("Sheet3").ChartObjects(Worksheets("Sheet3").ChartObjects.Count).Name = "Positive Distribution"
End Sub

Excel 2010.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
may the fact that im using excel 2003 have anything to do with it as i just created a chart, copied the test() u had in ur last post and nothing happened.
 
Upvote 0
i must be doing something stupid then. Thanks for ur help anyway though. I will try n see where I have screwed up.

Rgds

Scolty
 
Upvote 0
Working in Excel 2000. To verify that the name of the chart has changed, show the Drawing toolbar, click on the Select Objects icon (the northwest facing arrow), click on the chart, note the name in the address bar.
 
Upvote 0
Aye ok, i will open it up after work hrs and have a look and see if i can get it working again but i tried a little longer last night n i still had a blank chart, with just "series 1" on the right hand side.

Thanks again for ur help though :)
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

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