473,657 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel help... Automate Charts

135 New Member
Hi all. I am asking this question here because I have no idea where else to go with it. It involves VBA... but not Access. You guys have always been spot on with Access help so i thought maybe you could give me some direction or maybe tell me where to go with my question. I have an Excel question.

I have a list of data that is updated every day and exported from another program into an excel file. This data is in long columns of some 2500+ rows. The column headings are date, type, status, field name. Every block of 50 rows is various data for the same field name. I would like to automate chart making for each block of 50 rows. The chart will be exactly the same format with exactly the same amount of data. Here is what the macro creates for one chart:
Expand|Select|Wrap|Line Numbers
  1. Sub Macro12()
  2.     ActiveSheet.Shapes.AddChart.Select
  3.     ActiveChart.ChartType = xlLine
  4.     ActiveChart.SeriesCollection.NewSeries
  5.     ActiveChart.SeriesCollection(1).Values = "='Sheet1'!$D$2:$D$50"
  6.     ActiveChart.SeriesCollection(1).XValues = "='Sheet1'!$F$2:$F$50"
  7. End Sub
How to have a chart created to represent every 50 rows of data? I suppose i could copy the code 50 times and find out what cells would be included in each section... but that seems so archaic. Ideas? Or where I should go post this question? Thanks all.
Mar 12 '11 #1
9 3172
ADezii
8,834 Recognized Expert Expert
Just subscribing for now, will see if any ideas pop up in my head...
Mar 12 '11 #2
MyWaterloo
135 New Member
Ya... It seems like it shouldn't be too difficult: Code for chart creation; Code to move 50+ rows and create a new chart using next 50 rows; and so on...but I can't get my brain around it... or find any similar posts through an internet search that could help.
Mar 12 '11 #3
ADezii
8,834 Recognized Expert Expert
This Code has not been tested, so I really do not know how well, or if at all, it will work. You may have to tweak it a little, but hopefully it will point you in the right direction. Good Luck.
Expand|Select|Wrap|Line Numbers
  1. Dim intCtr As Integer
  2. Const conNUM_OF_ROWS As Integer = 2500
  3.  
  4. For intCtr = 2 To conNUM_OF_ROWS Step 50
  5.   ActiveSheet.Shapes.AddChart.Select
  6.     With ActiveChart
  7.       .ChartType = xlLine
  8.       .SeriesCollection.NewSeries
  9.       .SeriesCollection(1).Values = "='Sheet1'!$D$" & CStr(intCtr) & ":$D$" & CStr(intCtr + 49)
  10.       .SeriesCollection(1).XValues = "='Sheet1'!$F$" & CStr(intCtr) & ":$F$" & CStr(intCtr + 49)
  11.     End With
  12. Next
Mar 12 '11 #4
MyWaterloo
135 New Member
Wow! It worked perfect! I plugged in the code and boom! More charts than you can shake a stick at! If I could trouble you once more... How can I select the name for the charts? The Names reside in column B. I tried:
Expand|Select|Wrap|Line Numbers
  1.     Dim intCtr As Integer
  2.     Const conNUM_OF_ROWS As Integer = 2646
  3.  
  4.     For intCtr = 2 To conNUM_OF_ROWS Step 49
  5.       ActiveSheet.Shapes.AddChart.Select
  6.         With ActiveChart
  7.           ActiveChart.Name = "='Sheet1'!$B$" & CStr(intCtr) & ":$B$" & CStr(intCtr + 48)
  8.           .ChartType = xlLine
  9.           .SeriesCollection.NewSeries
  10.           .SeriesCollection(1).Values = "='Sheet1'!$D$" & CStr(intCtr) & ":$D$" & CStr(intCtr + 48)
  11.          .SeriesCollection(1).XValues = "='Sheet1'!$F$" & CStr(intCtr) & ":$F$" & CStr(intCtr + 48)
  12.        End With
  13.    Next
...but it doesn't work to try and name the charts like that. (I also discovered it is every 49 cells for chart data, hence the change in cells to count.) Also, all the charts are created as objects piled one on top of another, is there a way to tell them to spread out or align to a grid maybe? Like 5 across and 10 down? Thanks again, I will keep playing with this and keep checking back here also.
Mar 13 '11 #5
MyWaterloo
135 New Member
I figured out the naming issue:
Expand|Select|Wrap|Line Numbers
  1.         Dim intCtr As Integer
  2.         Const conNUM_OF_ROWS As Integer = 2646
  3.  
  4.         For intCtr = 2 To conNUM_OF_ROWS Step 49
  5.           ActiveSheet.Shapes.AddChart.Select
  6.             With ActiveChart
  7.               .ChartType = xlLine
  8.               .SeriesCollection.NewSeries
  9.               .SeriesCollection(1).Values = "='Sheet1'!$D$" & CStr(intCtr) & ":$D$" & CStr(intCtr + 48)
  10.               .SeriesCollection(1).XValues = "='Sheet1'!$F$" & CStr(intCtr) & ":$F$" & CStr(intCtr + 48)
  11.               .SeriesCollection(1).Name = "='Sheet1'!$B$" & CStr(intCtr + 48)
  12.         End With
  13.       Next
This works great to creat the charts and give them the appropriate names. There is one strange anomaly, the charts are all created with a phantom 2nd series called "Series2". I can't figure out why unless there is a default series when a chart is created. Se attached image. "Series2" is also empty of data.
Attached Images
File Type: jpg ScreenShot008.jpg (35.8 KB, 217 views)
Mar 13 '11 #6
MyWaterloo
135 New Member
Ok, the extra series is from the:
Expand|Select|Wrap|Line Numbers
  1. .SeriesCollection.NewSeries
This is not needed as the chart is created with a default series that the rest of the code then defines with .Values and the .XValues.


I would like to add another cell address to the naming code so the name is derived from column B & E.

Current Code:
Expand|Select|Wrap|Line Numbers
  1.  .SeriesCollection(1).Name = "='Sheet1'!$B$" & CStr(intCtr + 48)
Change to something like:
Expand|Select|Wrap|Line Numbers
  1. .SeriesCollection(1).Name = "='Sheet1'!$B$" & "='Sheet1'!$E$" & CStr(intCtr + 48)
, but obviously this doesn't work.


So I am still attempting to find a way to align the charts to a grid, and trying to pull the name from two different cells.
Mar 13 '11 #7
ADezii
8,834 Recognized Expert Expert
I would like to add another cell address to the naming code so the name is derived from column B & E.
Expand|Select|Wrap|Line Numbers
  1. Dim intCtr As Integer
  2.  
  3. intCtr = 2
  4.  
  5. MsgBox Worksheets("Sheet1").Range("B" & CStr(intCtr)) & _
  6.        Worksheets("Sheet1").Range("C" & CStr(intCtr + 48))
Mar 13 '11 #8
MyWaterloo
135 New Member
Thanks! That works... I also found code for aligning the charts:
Expand|Select|Wrap|Line Numbers
  1. Sub AlignCharts()
  2.   ' Jon Peltier (3/19/2008)
  3.   ' http://peltiertech.com/WordPress/
  4.   ' Changes MyWaterloo (3/13/2011)
  5.  
  6.   ' chart size - adjust as desired
  7.   Const nRowsTall As Long = 13
  8.   Const nColsWide As Long = 9
  9.  
  10.   ' chart layout - adjust as desired
  11.   Const nChartsPerRow As Long = 3
  12.   Const nSkipRows As Long = 2
  13.   Const nSkipCols As Long = 1
  14.   Const nFirstRow As Long = 3
  15.   Const nFirstCol As Long = 1
  16.  
  17.   Dim iChart As Long
  18.   Dim chtob As ChartObject
  19.   Dim dWidth As Double
  20.   Dim dHeight As Double
  21.   Dim rData As Range
  22.   Dim dFirstChartTop As Double
  23.   Dim dFirstChartLeft As Double
  24.   Dim dRowsBetweenChart As Double
  25.   Dim dColsBetweenChart As Double
  26.  
  27.   With Worksheets("Sheet2").Cells(1, 1)
  28.     dWidth = nColsWide * .Width
  29.     dHeight = nRowsTall * .Height
  30.     dFirstChartLeft = (nFirstCol - 1) * .Width
  31.     dFirstChartTop = (nFirstRow - 1) * .Height
  32.     dRowsBetweenChart = nSkipRows * .Height
  33.     dColsBetweenChart = nSkipCols * .Width
  34.   End With
  35.  
  36.   For iChart = 1 To Worksheets("Sheet2").ChartObjects.Count
  37.  
  38.     Set chtob = Worksheets("Sheet2").ChartObjects(iChart)
  39.  
  40.     With chtob
  41.       .Left = ((iChart - 1) Mod nChartsPerRow) * (dWidth + dColsBetweenChart) + dFirstChartLeft
  42.       .Top = Int((iChart - 1) / nChartsPerRow) * (dHeight + dRowsBetweenChart) + dFirstChartTop
  43.       .Width = dWidth
  44.       .Height = dHeight
  45.     End With
  46.  
  47.   Next
  48.  
  49.  
  50.  
  51.  
  52.  
  53. End Sub
Thanks for all your help ADezii, I really appreciate it.

God Bless,
MyWaterloo
Mar 13 '11 #9
ADezii
8,834 Recognized Expert Expert
@MyWaterloo - You really didn't need us at all! (LOL)
Mar 13 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1389
by: steve | last post by:
Hi, I have generated a datagrid with the following columns: | Date-Time | Station ID | Parameter1 | .... | Parameter 2| I would like to: Create an Excel file and preferably give the user a choice to create one separate Excel file per Station ID.
0
836
by: hemanth | last post by:
Hi, I have a problem at hand. There is a link http://alpha2.iimb.ernet.in/pgsem2006/interviewcall.html. Which displays the result of an exam. I want to check the result of all the 2000 candidates for my reference and sort it into passed and failed candidate. I want to automate this task can anyone help me. Typical registration number are 60010 and 60012. Thanks in advance.
6
1993
by: jtswim01 | last post by:
I have a very basic issue in excel and I can't for the life of me find the solution. I have a dense worksheet of data and I want to distill some of the information into a much shorter list. The data is ordered and the information I want to pull out from the big sheet and put in the little sheet occurs in the same column in every 30th cell. In my new sheet, I want my column of information to refer to every 30th cell. In other words, I want...
0
2566
by: johnlim20088 | last post by:
Hi, Hi someone can help me on this? Currently I have a Listdata.aspx page with datagrid, I wish to export my datagrid content to excel with following code ( with button export click event):- But when I run the code, it raise an error -> Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server" My Listdata.aspx page are place under MasterPage.aspx, which is inside Contentplace holder. how to...
5
1772
by: Louis | last post by:
I am trying to use php to update a spreadsheet (MS Excel or OpenOffice Calc) with data from MySQL. I looked into PEAR::Spreadsheet_Excel_Writer if it will do the job. If I understand it correctly, it basically creates spreadsheets, but not opening an existing spreadsheet and then updating and saving it, which is what I want to do. Do you know if there is any package out there that can do what I described?
2
5184
budigila
by: budigila | last post by:
Hiya peeps, Okies, I have been trying to work this out for a while now to no avail... I am a beginner to this whole coding thing but have made great strides in my project. Basically what I am trying to do is to convert an .xml using a .xsl to and using a java script to output it into a readable format within excel. I have been able to successfully use a javascript to combine my .xml and .xsl but cannot figure out how to have it output to...
10
4988
KodeKrazy
by: KodeKrazy | last post by:
I'm trying to read an Excel worksheet and do a find/replace for all of the commas "," in any of the cells in the sheet and replace them with a dash "-" I can get as far as getting the workbook opened but I'm not sure where to go from here. Is there a simple method to accomplish this? Below is the code I have so far: Dim exl As Microsoft.Office.Interop.Excel.Application Dim sht As...
0
856
by: arunbalait | last post by:
Hi How can I display charts in VB.Net with multiple Y-Axes.? I need to display chart with multiple Y-Axis, but with Ms.Chart control there are options for 2 Y-Axis. but i want more than that. Are there any controls to do so or any ocx etc.,?? Help me plz. Need an immediate solution. Thanx in advance.
0
2876
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
7
3325
Catalyst159
by: Catalyst159 | last post by:
I want to automate the process of listing items for selling on ebay. Any help would be greatly appreciated. I would like to try and use Microsoft Access 2007 with VBA to accomplish this, but I am open to other suggestions and recommendations.
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.