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

Home Posts Topics Members FAQ

Basic Excel Macro to create graphs

78 New Member
I have a simple Excel Spreadsheet that continuously updates with data (both columns and rows). I am trying to build a macro that will start with the first row (which is actually row 2) and graph all the data in that row until an empty cell is found and stop. Then I need it to loop to the next row and graph that row until an empty cell found. I need it to continue row by row until and empty cell is found in Column A. I'd like each of the graphs to be on a seperate tab.

I've tried to use suggestions online and plug and play with different code and have only created a mess. Any help on how to set this up would be greatly appreciated!

Thanks.
Dec 10 '13 #1
6 6191
ADezii
8,834 Recognized Expert Expert
The following Code will dynamically create a 3D Clustered Column Chart on Sheet1 based on Data contained in Cells starting from Row2/Column A. The Data will consist of all Columns in Row 2 whose Cells are not Empty. No Validation is performed on the Values within these Cells.
Expand|Select|Wrap|Line Numbers
  1. Dim intCol As Integer
  2. Dim intRow As Integer
  3. Dim rng As Excel.Range
  4.  
  5. intRow = 2
  6. intCol = 1
  7.  
  8. Do Until Cells(intRow, intCol).Value = ""
  9.   intCol = intCol + 1
  10. Loop
  11.  
  12. Set rng = Range("A" & CStr(intRow) & ":" & Chr$(intCol + 63) & CStr(intRow))
  13.     rng.Select
  14.  
  15. Charts.Add
  16.  
  17. ActiveChart.ChartType = xl3DColumnClustered
  18. ActiveChart.SetSourceData Source:=rng, PlotBy:=xlRows
  19. ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
  20.  
  21. With ActiveChart
  22.   .HasTitle = False
  23.   .Axes(xlCategory).HasTitle = False
  24.   .Axes(xlSeries).HasTitle = False
  25.   .Axes(xlValue).HasTitle = False
  26. End With
This should be a good starting point for you.
Dec 10 '13 #2
WannabePrgmr
78 New Member
Thank you for the great start! This worked exactly like you said it would, however after the chart was created, a run-time error came up stating "The specified dimension is not valid for the current chart type". When I click "Debug", it highlights:

Expand|Select|Wrap|Line Numbers
  1. ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Dec 11 '13 #3
WannabePrgmr
78 New Member
@ADezii

I apologize. I didn't know if I should've replied here or post new, so I did both.

Thank you for the great start! This worked exactly like you said it would, however after the chart was created, a run-time error came up stating "The specified dimension is not valid for the current chart type". When I click "Debug", it highlights:

Expand|Select|Wrap|Line Numbers
  1. ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Thanks!
Dec 11 '13 #4
ADezii
8,834 Recognized Expert Expert
Try changing the offending Line of Code to:
Expand|Select|Wrap|Line Numbers
  1. ActiveChart.Location Where:=xlLocationAsNewSheet
Dec 11 '13 #5
WannabePrgmr
78 New Member
@ADezii

Perfect! Thanks for your help! After messing around for an hour or two, I figured out the rest of what I needed for this as well! Thanks for getting me started and following up!
Dec 11 '13 #6
ADezii
8,834 Recognized Expert Expert
Your are quite welcome. I guess you are no longer a WannebePrgmr but a FullFledgedPrgmr (LOL).
Dec 11 '13 #7

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

Similar topics

2
11091
by: Mrs Howl | last post by:
I don't know if there's even a way to do what I want. I click on a button in an Access form, and it opens an instance of Excel, and opens a workbook and runs a macro that's in it. So far, fine,...
0
2073
by: Alex | last post by:
i have a module in Access which opens an existing Excel file and envokes a macro within the Excel file to draw graphs. now i am trying to convert the Excel macro to an Access one so that the...
2
6369
by: CR | last post by:
How do you "step into" an excel macro when using the VB.NET debugger? I'm using excel 2000. Here's is how I did it with VB6: Dim objExcel As Excel.Application objExcel = New...
1
1611
by: etangman | last post by:
Hello people. This is quick and easy I just can't figure out the correct syntax. Help appreciated. I'm attempting to create an Excel macro that replaces cell contents on one sheet with a...
2
4463
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I exported a gridview to excel spreadsheet. I want to adjust the column width of the excel spreadsheet. Is it possible to create Excel macro from C# to adjust the column width...
1
2756
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I exported a gridview to excel spreadsheet. I want to adjust the column width of the excel spreadsheet. Is it possible to create Excel macro from C# to adjust the column width...
0
4141
by: kittu513 | last post by:
Hi I need some help regarding the alignment of the value in the active cell. my code is like this (its VB code to implement an Excel macro) Range("B1").Select ActiveCell.Offset(50,...
3
4199
by: redbenn | last post by:
Hello, I am trying to create an excel macro, that when clicked... a specific cell will match a record in my database, and update certain fields in this record. The Excel file will have a cell...
1
6172
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
7
1749
by: preciouslife73 | last post by:
'actually I have a macro that exports multiple querys or table into many excel spreadsheet with multiple worksheets. 'but this is just to test the Excel Macro to work on the exported files. 'is...
0
7260
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,...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
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,...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
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,...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.