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: - Sub Macro12()
-
ActiveSheet.Shapes.AddChart.Select
-
ActiveChart.ChartType = xlLine
-
ActiveChart.SeriesCollection.NewSeries
-
ActiveChart.SeriesCollection(1).Values = "='Sheet1'!$D$2:$D$50"
-
ActiveChart.SeriesCollection(1).XValues = "='Sheet1'!$F$2:$F$50"
-
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.
9 3172 ADezii 8,834
Recognized Expert Expert
Just subscribing for now, will see if any ideas pop up in my head...
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.
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. - Dim intCtr As Integer
-
Const conNUM_OF_ROWS As Integer = 2500
-
-
For intCtr = 2 To conNUM_OF_ROWS Step 50
-
ActiveSheet.Shapes.AddChart.Select
-
With ActiveChart
-
.ChartType = xlLine
-
.SeriesCollection.NewSeries
-
.SeriesCollection(1).Values = "='Sheet1'!$D$" & CStr(intCtr) & ":$D$" & CStr(intCtr + 49)
-
.SeriesCollection(1).XValues = "='Sheet1'!$F$" & CStr(intCtr) & ":$F$" & CStr(intCtr + 49)
-
End With
-
Next
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: - Dim intCtr As Integer
-
Const conNUM_OF_ROWS As Integer = 2646
-
-
For intCtr = 2 To conNUM_OF_ROWS Step 49
-
ActiveSheet.Shapes.AddChart.Select
-
With ActiveChart
-
ActiveChart.Name = "='Sheet1'!$B$" & CStr(intCtr) & ":$B$" & CStr(intCtr + 48)
-
.ChartType = xlLine
-
.SeriesCollection.NewSeries
-
.SeriesCollection(1).Values = "='Sheet1'!$D$" & CStr(intCtr) & ":$D$" & CStr(intCtr + 48)
-
.SeriesCollection(1).XValues = "='Sheet1'!$F$" & CStr(intCtr) & ":$F$" & CStr(intCtr + 48)
-
End With
-
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.
I figured out the naming issue: - Dim intCtr As Integer
-
Const conNUM_OF_ROWS As Integer = 2646
-
-
For intCtr = 2 To conNUM_OF_ROWS Step 49
-
ActiveSheet.Shapes.AddChart.Select
-
With ActiveChart
-
.ChartType = xlLine
-
.SeriesCollection.NewSeries
-
.SeriesCollection(1).Values = "='Sheet1'!$D$" & CStr(intCtr) & ":$D$" & CStr(intCtr + 48)
-
.SeriesCollection(1).XValues = "='Sheet1'!$F$" & CStr(intCtr) & ":$F$" & CStr(intCtr + 48)
-
.SeriesCollection(1).Name = "='Sheet1'!$B$" & CStr(intCtr + 48)
-
End With
-
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.
Ok, the extra series is from the: - .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: - .SeriesCollection(1).Name = "='Sheet1'!$B$" & CStr(intCtr + 48)
Change to something like: - .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.
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.
- Dim intCtr As Integer
-
-
intCtr = 2
-
-
MsgBox Worksheets("Sheet1").Range("B" & CStr(intCtr)) & _
-
Worksheets("Sheet1").Range("C" & CStr(intCtr + 48))
Thanks! That works... I also found code for aligning the charts: - Sub AlignCharts()
-
' Jon Peltier (3/19/2008)
-
' http://peltiertech.com/WordPress/
-
' Changes MyWaterloo (3/13/2011)
-
-
' chart size - adjust as desired
-
Const nRowsTall As Long = 13
-
Const nColsWide As Long = 9
-
-
' chart layout - adjust as desired
-
Const nChartsPerRow As Long = 3
-
Const nSkipRows As Long = 2
-
Const nSkipCols As Long = 1
-
Const nFirstRow As Long = 3
-
Const nFirstCol As Long = 1
-
-
Dim iChart As Long
-
Dim chtob As ChartObject
-
Dim dWidth As Double
-
Dim dHeight As Double
-
Dim rData As Range
-
Dim dFirstChartTop As Double
-
Dim dFirstChartLeft As Double
-
Dim dRowsBetweenChart As Double
-
Dim dColsBetweenChart As Double
-
-
With Worksheets("Sheet2").Cells(1, 1)
-
dWidth = nColsWide * .Width
-
dHeight = nRowsTall * .Height
-
dFirstChartLeft = (nFirstCol - 1) * .Width
-
dFirstChartTop = (nFirstRow - 1) * .Height
-
dRowsBetweenChart = nSkipRows * .Height
-
dColsBetweenChart = nSkipCols * .Width
-
End With
-
-
For iChart = 1 To Worksheets("Sheet2").ChartObjects.Count
-
-
Set chtob = Worksheets("Sheet2").ChartObjects(iChart)
-
-
With chtob
-
.Left = ((iChart - 1) Mod nChartsPerRow) * (dWidth + dColsBetweenChart) + dFirstChartLeft
-
.Top = Int((iChart - 1) / nChartsPerRow) * (dHeight + dRowsBetweenChart) + dFirstChartTop
-
.Width = dWidth
-
.Height = dHeight
-
End With
-
-
Next
-
-
-
-
-
-
End Sub
Thanks for all your help ADezii, I really appreciate it.
God Bless,
MyWaterloo
ADezii 8,834
Recognized Expert Expert @MyWaterloo - You really didn't need us at all! (LOL)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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.
|
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...
|
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...
|
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?
| |
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...
|
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...
|
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.
|
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.
...
|
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.
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |