Referring To Chart In VBA Code

Jul 31, 2012

My first version is this:

Code:
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).XValues = "=DATA!$A$8:$A$19

Works without problems, but I really don't want to use "ActiveSheet" there

I changed it to:

Code:
Dim chtTR As ChartObject
Set chtTR = shtData.ChartObjects("Chart 1")
chtTR.SeriesCollection(1).XValues = "=DATA!$A$8:$A$19"

and it gives me

"Object doesn't support this property or method."

View 3 Replies


ADVERTISEMENT

Referring To Other Workbooks Via VBA Code

Oct 5, 2009

I'm trying to use VBA to write from one workbook to another. I'm trying to populate other workbooks from a single 'control' workbook with a template.

I've managed to figure out how to open up Excel workbooks within a directory (this needs to be done multiple times) supplied by the user, then retrieve information from it to be collated, but I can't for the life of me figure out how to write to the file that I've opened.

I've got the code below, and it's very scrappy as I've been trying lots of different things but nothing's worked. I'll try and highlight as best as I can where I'm having difficulties, as I get the "object not defined" or some such error.

View 12 Replies View Related

Referring To Code From Multiple Events

Jul 14, 2006

If I have a button on each of numerous sheets, how do I get all of the buttons to refer to the same bit of code, without having to copy it to the click event of each?

View 4 Replies View Related

Auto Update Of Totals By Referring To A Code

Jun 14, 2014

The below is a data sheet which is going to be designed to keep the records of "sending and receiving" details of wash-garments from a garment factory.

Descriptions;

01. Starting from B12, the dates of sending and receiving are entered in the sequence they occur. Both sending and receiving can occur on the same date.

02. Starting from C12, there are reference codes related to the activity, if Sending the letter is entered as "S", and if receiving it is entered as "R". I included this for the calculation or sorting purpose.

03. Columns D to J includes the break down of sizes of the quantities sent or received.

04. column K simply calculates the totals of the columns from D to J.

Requirement : I need to have the totals of each size wise quantities sent and received in the "summary table" as follows;

>> Size wise totals of "sent qtys" to be shown in D5 to J5(referring to the code "S")
>> Size wise totals of "received qtys" to be shown in D6 to J6(referring to the code "R")
>> The dates to be updated and displayed"automatically" in the rows of the column B, when the code letters("S" or "R") is entered in the column "C"

Special Remarks : The last date of sending or receiving cannot be predefined, the rows(dates)will be kept adding according to the way sending and receiving may occur.

View 14 Replies View Related

Code For Form Referring To Cell Deletion

Feb 6, 2007

This time ive created a visual basic form that asks for a row number and when you put a row number in this form it deletes what is in column A, B and C of that row and shift the rows up so that there are no gaps between the data in the rows.

I need to know what code i would have on the 'delete' button of the form.

If you want me to describe it any further i would be happy to, just ask.

View 9 Replies View Related

Referring To A Worksheet Cell Within The Vba Code Of A Custom Function

Jul 26, 2006

How does one pick up the data contained in a worksheet cell (say B5) and use it in the vba code of a custom function without passing the cell as an arguement

View 3 Replies View Related

Chart SourceData Code

Jun 14, 2007

Creating a vba program that automatically generates charts. Looking for the easiest way to get the range of the data that the chart is using (later in program). Noticed the SetSourceData method but dont see a GetSourceData (that returns a range).

View 3 Replies View Related

Bring Chart To The Front VBA Code?

Nov 20, 2012

I have chart object in the sheet. I wrote code that makes the cart big, but it is not on top of other things. I need to add a snippet of the code that would make it "bring to the front".

View 1 Replies View Related

Resize Bars Of Bar Chart Using VBA Code?

Nov 30, 2012

i need to prepare a bar chart from some data. what i want to do is that i want bar size to be fixed (larger than what automatically comes) and then excel changes the size of chart based on no of x-axis values keeping the bar size fix.

(currently chart size is fixed and bar size changes accordingly, i just want the reverse that bar size is fixed and chart size changes according to no of values in axis)

View 4 Replies View Related

Edit Chart Code To Exit If

Oct 13, 2008

I just wonder if we can have the code to exit if G2 returns an even number, as 2, 4, 6 etc?

Sub Listbox3_Change()

If ActiveSheet.Index 1 Then Exit Sub
Application.ScreenUpdating = False

With Sheets(1)
.Unprotect "mypsw"
.Range("G2").Value = ActiveSheet.ListBoxes(Application.Caller).Value
With .ChartObjects("Chart 2").Chart.Axes(xlValue)
If VBA.VarType(Sheets(1).Range("D1").Value) = VBA.vbError Then Exit Sub
If VBA.VarType(Sheets(1).Range("E1").Value) = VBA.vbError Then Exit Sub

.MinimumScale = (Sheets(1).Range("D1") - 0)..............

View 9 Replies View Related

Color Code Chart Columns

Dec 11, 2006

I am trying to color code the cubes in my chart. I'd like to be able to be able to specify a specific color per cube. What code what I write for the Sheet to do this?

View 5 Replies View Related

Create Chart Automatically Via Code

Dec 19, 2006

to write a code that would create a chart automatically in another worksheet when a button is clicked.

I have attached the sample data that I am working on.
Each row in the sheet represent 3 coordinates, which are:
coordinate # 1 = start, 0
coordinate # 2 = centre, level
coordinate # 3 = end, 0

View 6 Replies View Related

Chart Alignment Code Multiple PCs

Jun 28, 2007

These charts are generated via a macro and have to be aligned using VBA.

The charts look fine on my screen bu their alignments and position are messed up when another person uses it on another computer.

This is the code i am using to align the charts

chartwidth = 300
chartheight = 200
With ActiveSheet.Shapes("Chart 1")
.Width = chartwidth * 2 + 10
.Height = chartheight
End With

With ActiveSheet.Shapes("Chart 2")
.Width = chartwidth
.Height = chartheight
End With

With ActiveSheet.Shapes("Chart 3")
.Width = chartwidth
.Height = chartheight
End With
ActiveSheet.Shapes("Chart 1").IncrementLeft -128.25
ActiveSheet.Shapes("Chart 1").IncrementTop -75
ActiveSheet.Shapes("Chart 2").IncrementLeft 182.25
ActiveSheet.Shapes("Chart 2").IncrementTop 139.5
ActiveSheet.Shapes("Chart 3").IncrementLeft -126.75
ActiveSheet.Shapes("Chart 3").IncrementTop 138

View 3 Replies View Related

Chart Code With SetElement Fails In Pre 2007

Aug 22, 2008

I wrote this code so that someone else can keep track of a certain bond. It will provide him with returns and a chart between 2 periods. I wrote it on Office 2007 and it works for me, from the begining I wrote the code in an office 97-2003 compatible file. The worksheet is attached.

Sub Grafico()
Dim FechaGraficoInicial As Date 'Fecha de referencia para el rango
Dim FechaGraficoFinal As Date
Workbooks("Julius Baer.xls").Activate 'Para evitar un error, NO BORRAR
Worksheets("Precios").Activate
Columns("G:G").Select
Selection.ClearContents
Workbooks("Julius Baer.xls").Activate
Worksheets("Rentabilidades").Activate
FechaGraficoInicial = Worksheets("Rentabilidades").Range("B22")
FechaGraficoFinal = Worksheets("Rentabilidades").Range("B23")
i = 0
Condicional = 0 'Determina si el grafico se hace o no..........................

View 2 Replies View Related

Chart Title Manipulation With Macro Code

Sep 2, 2006

I have a program that updates values quarterly when run. The spreadsheet that it works with also contains a couple of pie charts that correspond to the updated data. the charts only have one series with category values. I recorded a macro to see the code excel uses for creating a new chart and tried to modify the statements to my needs but have been running into runtime error 1004 ("Method ' Cells' of Object '_Global' failed"). The code is as follows I don't have any trouble until the last two statements.

Sub Chart_Updater()
Sheets(Chart1var).Select
With ActiveChart
.HasTitle = True
If Chart1var = "COLI VUL 1 Fund Chart" Then
.ChartTitle.Text = "COLI VUL 1 Allocation by Fund Provider " _
& sday & "-" & sday & "-" & Lyear
ElseIf Chart1var = "COLI VUL 2 Fund Chart" Then
.ChartTitle.Text = "COLI VUL 2 Allocation by Fund Provider " _
& sday & "-" & sday & "-" & Lyear
ElseIf Chart1var = "COLI VUL 7 Fund Chart" Then
.ChartTitle.Text = "COLI VUL 7 Allocation by Fund Provider " _

The variables fundtr1, fundtr2, and emptycolvar are public, and are all returning values, so there is no problem there. Also I can't use ranges like "A1:F7" because the range needs to be variable.

View 5 Replies View Related

Code To Change Chart Source Data

Jul 16, 2007

I am in the middle of building a macro for some data to be automated. I have two sheets, one of which has an existing chart but the data has been removed so now there is no values on the chart. I then have a second sheet with data on it. The range is b4:c16. I want to point this data onto my chart on the other sheet.

View 2 Replies View Related

Change Chart Height & Width Code

Dec 21, 2007

How do I write a short piece of code that defines the specific height and width that I want to assign to an existing chart. The code will be added to existing code that I have that formats the chart in other ways. This needs to be able to work with any active chart selected, not a specific named chart.

View 2 Replies View Related

Date Based Bar Chart Macro Code

Mar 21, 2008

I am working on a manning document which tells me when people report, and depart based on their job position. I have all of the info in one worksheet, and want to generate a bar like graph on another worksheet in the workbook (by just changing the cell color for ease) for a snapshot to view holes in job positions.

The snapshot worksheet has the list of jobs on the left, and months/years in a line acorss the top i.e.

2006
| J | F | M | A | M | J | J | A | S | O | N | D |
Job Position X X X X X X
Job Position X X X X X X

Here was the code I started with, and it doesn't do anything!

Private Sub Workbook_CreateCalendar(ByVal Sh As Object, ByVal Target As Range)

Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim Fcol As Date
Dim Lcol As Date
Dim Lencol As Long
Dim CalcMode As Long
Dim ViewMode As Long
'Set the Start Date of your Sheet
Dim DatTim1 As Date
DatTim1 = #1/1/2006#

View 5 Replies View Related

Delete Chart Series Via Macro Code

May 27, 2008

I have a spreadsheet (see attached) in which there are many series and i want to be able to delete most of the series except the first 4.

(The 0%, 5% 10% air voids and the 95% comp line)

iv got this code, which is attacted to a command button, which works fine to delete all the series but makes the graph a blank white box. id prefer it so it delete just the series not the graph "picture?" ...

View 7 Replies View Related

Macro Code To Add More Rows To Existing Chart

Jun 17, 2008

I have managed to create something similar to what i am working for using an example from Lacher and Gant Charts. i am now stuck as I can enter more than 40 status as it then gives me an error. The following is the code: Can any1 highlight where i need to make any changes to stop the error from occuring:

Option Explicit
Sub CreateTimeChartData()
Dim vTimeData As Variant
Dim i As Integer
Dim sRoom As String
Dim vLastEndTime As Variant
Dim oSeries As Series
' set up
Application. ScreenUpdating = False
Application.DisplayAlerts = False
' create chart data worksheet
With Worksheets("TimeData"). Range("TimeList"). CurrentRegion
.Sort Key1:="Room", Key2:="Start Time", Header:=xlYes
vTimeData = .Value
Worksheets.Add
On Error Resume Next
Worksheets("ChartData").Delete..........................

View 3 Replies View Related

Fire Chart VBA Code On Validation List Choice

May 8, 2009

very complex spreadsheet for weight & balance calculations. It's to the point where everything works perfectly in Excel 2007, but it must be used primarily with Excel 2003. Discovered that a crashing problem had to do with condtional formatting, that's all been cleared and will soon be fixed, but there's one that I just can't quite figure out.

I'm using the worksheet change event to trigger the update of charts... In this case, it's looking at a particular cell that has data validation on a dropdown as the trigger. Works perfectly in 2007, and if I put a msgbox prompt in to be launched by a change of that cell, it launches. I can put the chart update code in a separate sub and launch it manually every time, but I cannot call it from the worksheet change.

I've included attachments showing what I believe are the relevant bits of code -

View 9 Replies View Related

Add Secondary Chart X-axis Below Primary Via Macro Code

Apr 27, 2008

In VBA, how to add a secondary x-axis in the lower portion of the chart if I already have the primary axis in the upper part?

This code

ActiveChart.HasAxis(xlCategory, xlSecondary) = True

just adds it to the upper if I have the primary at lower.

View 4 Replies View Related

Macro Code To Count Number Of Chart Series

Jul 1, 2008

I have about 50 lincharts that I wont to update with VBA but they have different number of series. Some have two series, some three and others four. Is there a way to count how many series a chart has? Otherwise could I get tips on how to approach this problem.

View 2 Replies View Related

Referring Cells

Jun 17, 2009

I am trying to refer to a cell. Not sure if thats a good way to put it.

Example: I am in Cell B1 and I want to have a formula that says if C2 is 5 then A1 is 5, else B1 is 500.

I need A1 to be completely blank with the formula only in B1 and C2 has the number typed in it.

How can I put a number in A1 without having a formula or any text in that cell (A1)?

View 9 Replies View Related

Color Code Data Points On A Scatter Chart (2007)

Jun 12, 2009

Does anyone know if there's a way to color code points on a scatter chart based on their values in a "3rd dimension" (i.e. other than the 2 dimensions represented by the chart axes).

You might imagine a scatter chart that plots transactions by price (y) and units purchased (x).

In that scenario, it might also be nice to color code each point by the region that made the sale.

The only way I know to do this is to manually create separate columns of data for each region, so that each region can be plotted on the scatter chart as a separate data series.

But since I'd like to experiment with several color coding alternatives, I'm wondering if there isn't a simpler way...

For instance, Rob Bovey's "XY Chart Labeler" can add data point labels to a scatter chart...

Is there, perhaps, another add-in that might enable color coding of data points based on a 3rd set of values?

View 9 Replies View Related

VB Code To Make XY Scatter Chart (relative To Input Cell)

Jul 17, 2014

I have a project coming up where I will receive tables in a certain format. I want to be able to create a macro that well create a chart based on a single inputted cell (start of data). The chart will have 4 series and five values per series. See the link below for sample data! The first data point is not in the same place in the sheet, but the table will have the rest of the data relative to that!

[URL] .......

View 2 Replies View Related

Broken Line Chart Code Turning Lines Black

May 24, 2007

creating breaks in the line this script now simply turns the line black.

View 9 Replies View Related

Change Order For Chart Series Collection Macro Code

Mar 18, 2008

I have a bar graph with 2 series of data. Anyone knows how I can specify the order in which they appear? code looks similar to the following. The bar graph shows the second series before the first series. How do I reverse the order?

With cht
.ChartType = xlColumnClustered

' first data series
Set ser = .SeriesCollection.NewSeries
With ser
.Values = someValues
.XValues = someValues
End With

' second data series
Set ser = .SeriesCollection.NewSeries
With ser
.Values = someValues
.XValues = someValues
End With

View 2 Replies View Related

Create Surface Chart Via Macro Code Based On Selection

May 28, 2008

I want to write a macro to add a surface chart for a Data Range which includes 6000 data points. But the series selected for the chart don't cover all Data Ranges, only part of them.

Public Sub AddChart2(LastRow As Integer, LastCol As Integer)

Dim cht As ChartObject, currentSheet As Worksheet
Dim rng As Range, newRow As Range, srcRange As Range
Dim colIdx As Integer

colIdx = 5

View 7 Replies View Related

Referring To Functions Within Function IF And THEN VBA

Nov 5, 2012

So far I have 2 Functions with a sub to test to do certain calculations.

VB:
[B]Private Sub test_getBaristaSalary()
Dim InputYear As Integer
InputYear = InputBox(Prompt:="How many years of Experience?")

[Code].....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved