Chart Range Variable?

Feb 22, 2010

I am fairly new to using vba in excel, but not vba entirely so I know there is a way to accomplish what I need. I need to specify the range for a chart using variables

1. The row variable will be a selection on a combo box
2. The column variables will be mulitple selections on a list box
3. These cells will not be concurrent, for example:
I6, K6, O6

This is all in a vba macro button

View 2 Replies


ADVERTISEMENT

Variable Range For Chart Using VBA

Feb 27, 2012

I recorded a simple macro to create a chart using VBA. The code for the macro is:

Code:
Sub Add_Chart1()
'
' Add_Chart1 Macro
'
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine

[code]....

The problem is that I need the code to select a variable range from C4 to the last used row in column C for the x values and from G4 to the last used value in column G.

I tried to modify the code to do that by doing the following:

Code:
Sub Add_Chart1()
'
' Add_Chart1 Macro
'
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine

[code]....

When I run the macro, I get an error 91, "Object variable or With block variable not set"; Also the chart is created but not correctly.

I created a sub called "range" (see below) and it correctly selects selects the C or G ranges, however, the argument does work in the chart macro.

Code:
Sub Range()
Sheets("Sheet1").Range("C4:C" & Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Row).Select
Sheets("Sheet1").Range("G4:G" & Sheets("Sheet1").Range("G" & Rows.Count).End(xlUp).Row).Select
End Sub

View 2 Replies View Related

Variable Range For Chart Series Data

May 23, 2008

I have data which is imported from a txt file and always starts at the same row (R19) but is variable in length (end of data R??). I want to be able to select the chart xvalues (R19C10:R?C10) and values (R19C4:R?C4) based on the number of cells with data in them for a given column. In addition I believe I'm having troubles with sheet references, when the txt file is opened the sheet name is set to the file name, since I want to use this macro on many different files I need the sheet referencing code to account for this. Anyway here is the section of code which seems to be giving me trouble (the initial sections just create a new column of data which needs to be referenced as the xvalues) ...

View 3 Replies View Related

Chart/Graph Changing/Variable Range

May 28, 2008

I have a vast database where I have linked charts. I send the data from a macro to the database and sometimes there are 1000 inputs and sometimes there are only 20.
How would i set up my charts to only graph the inputs that are present?

View 7 Replies View Related

String Variable To Call Defined Range Variable

Nov 10, 2006

Say you define a public range variable called Inputworksheet and you set it to refer to the worksheet called Inputworksheet. You have a separate string variable with the value Inputworksheet. How do you get this string variable value to call/control the range variable Inputworksheet?

I am getting an excel worksheet value from a lookup function that corresponds to the name of a VBA range variable. Once I have this worksheet value, I would like to use the range variable that has the same name as the worksheet value.

View 5 Replies View Related

Use VBA Variable In Chart Series

Oct 2, 2012

I'm attempting to create a dynamically built donut chart using VBA, but I'm having trouble inserting a variable to be used as one of the values.

The chart graphs 3 data points:
ASC GP - Located in cell T4
ACC GP - Located in cell AE4
ACT GP - variable called LocSumActGP

The code snippet I assumed would work looked like this:

Code:
.SeriesCollection(1).Values = "='Location Summary'!$T$4,'Location Summary'!$AE$4," & LocSumActGP

But it doesn't seem to like that.

View 2 Replies View Related

Autofill With Range That Is Column Variable And Row Variable

Apr 4, 2008

I am trying to autofill dynamic ranges that have column variables (d) and row variables (x)... I am having a hard time with the syntax on this

View 9 Replies View Related

XY Chart With Colored Symbols Indicating A Third Variable

Nov 22, 2013

Data set has three columns: dates, cycle times for event and event type. I want to create a XY chart with cycle time ploted against date (filled circles connected by line). I further want the color of each of these symbols to change as a function of event type. I vizualize a chart where the symbols might be red, red, blue, red, yellow where red indicates event type 1, blue event type 2 and yellow event type 3. how I might build this chart.

View 1 Replies View Related

Line Chart With Variable Data Series

Jan 17, 2014

I am trying to produce a line chart, which will use imported data on a separate sheet (but within the same workbook)

The imported data can be of different sizes ie column widths and length. Some columns may contain only zero and should not be included in the chart, and will be to right of the data.

I have created a named range for the data series called ChartData using =OFFSET(Data!$C$1,0,0,info!$C$7,info!$A$2) - C7 and A2 are calculations to set column and row sizes. I have tried to use this as the chart's data series, but without success.

View 4 Replies View Related

Defining Variable Data Row For Chart Series

Oct 5, 2006

I want the below code to run from R1C10 (i.e. cell J1) to the end of the data in the row, which will vary in position, rather than having to define where the end of the row will be beforehand (i.e. R1C21).

Is this possible?

View 9 Replies View Related

Setting Column Chart Data Using VBA For Variable Ranges

Mar 10, 2014

I have some code to plot a column chart of data but it isn't working as expecting at the moment. The code is below. The variable binCounter is a count of how many cells in a range that I want to plot on the chart.

However, what I am finding is that the first couple of cells in the range appear as the series name with the rest appearing as the data in the chart. Secondly, the chart appears with the axis labels 1,2,3 etc when I have some custom ones I would prefer to use. How do I go about setting this property, as I can only find options on setting the axis title There is a lot of stuff on XY charts on Google but I can't find much on column charts unfortunately .

VB:
'activate sheet and chart
Worksheets("Home Page").Activate
ActiveSheet.ChartObjects("Histogram").Activate

'set variables for chart
With ActiveChart

[Code] .....

View 1 Replies View Related

Set Range Variable Using Variable Row Number

Mar 11, 2008

I am using a variable named " Totals" as a range type to refference the range in a formula. It works the way I have it.

Dim Totals As Range
Set Totals = [U37: AE37]

Now instead of the absolute refference, I would like to change the row refference by an offset of my current row, using a formula with a varriable. The columns stay the same.

View 3 Replies View Related

Autofill In Macro Range Is Constant How Can I Code To Be A Variable Range?

Feb 19, 2010

I am trying to write a macro which will autofill specific columns. The macro will set the range from the start of my autofill to the end of my autofill as a constant range.

The problem I need to get around is the end of my range can always change each time I run the macro. For instance, the first time I run the macro I may only need to autofill from row 4 to row 15. The next time, I may only need to autofill from row 4 to 23 (because of user updates). How can I make the end of my range not be a constant address but variable?

View 6 Replies View Related

Getting Chart Range From Range Address Contained In A Cell

Dec 3, 2013

I have a Choose function that is used to determine which range I need. e.g. =Choose(Choice,Cell,Cell,...).

In each corresponding "Choice" cell is a typed range. e.g. $B$33:$L$70

I'm looking for a way to be able to use this typed range as the range for some chart data.

View 2 Replies View Related

Select Range In Worksheet Where Last Cell In Range Is Variable?

Jan 27, 2012

I am trying to write code to select a range in a worksheet where the last cell in the range is variable.

Sub DataTest()
Dim LastColumn As Integer
Dim LastRow As Long
Dim LastCell As range

[Code].....

View 8 Replies View Related

Assign Named Range To A Vba Range Variable?

Jan 25, 2013

I have a named range, called SubjectNamesPastoral on a worksheet called Worksheets("Group to Teacher")

I can't assign the named range to the rngSubjectFamilyRangeOnSubjectUsedSheet variable in vba.

the first two lines of code work fine, the msgbox shows "E100:E105", happy days!

However when I try to assign the same range to the rngSubjectFamilyRangeOnSubjectUsedSheet variable, the debugger runs past the 'Set' line without error, but throws 'error 91' at the second msgbox.

VB:
thisString = "SubjectNames" & strSubjectFamilyOfGroup

MsgBox Range(thisString).Address

Set rngSubjectFamilyRangeOnSubjectUsedSheet = Worksheets("Group to Teacher").Range(thisString)

View 1 Replies View Related

Copy A Range And Paste It Over A Variable Range

Jul 16, 2009

I am using the code below to copy a range and paste it over a variable range.

View 4 Replies View Related

Set Range Variable To Growing Dynamic Range

Mar 6, 2008

I have been working on part of the code for my spreadsheet and it works fine in the spreadsheet “Databaseform” however when I copied the code to my master spreadsheet “Paul_PartLocDBCombo” it does not work, I get the error:

Method ‘ range’ of object ‘_worksheet’ failed
The code is then highlighted in yellow, the code is:
Set rng = wksPartsData.Range("a1", Range("a65536").End(xlUp))

Meaning this part is incorrect but I don’t know why? To work it: go to Databaseform and press start. Enter 7mm in the product field and press find all. It will then return all the matching results in the userform. Its this I want to try and achieve on the other spreadsheet when the button find label is pressed.

View 3 Replies View Related

Chart Range

Mar 24, 2009

I have daily information that I am tracking for the year. From this information I am making 12 monthly charts. When I started the file I was able to format the X axis and choose the minimum and the maximum value it would graph (1st day of month/last day of month). The graphs also show the trendline.

For some reason the February chart is set to March. When I click on the X axis and go to format axis option, I no longer have the option to set the minimum and maximum values. The first thing is lets me adjust is the interval between tick marks.

The vertical axis still lets me choose the min and max values.

View 9 Replies View Related

Range Variable

Oct 25, 2007

I have a range "C1:Cx" where i want x to be the value from a value "overallLastRow". How do I write this?

View 9 Replies View Related

Specifying A Range Using A Variable

Oct 26, 2008

This is just a simple question but I can't seem to find the answer in any of the hepl files. I want to refer to a range by using a variable but can't get the syntax right.

for example instead of

View 2 Replies View Related

Sum Variable Range

Feb 19, 2009

I am in need of code to sum the above range. But it is different range every day. My company will add the deposit amounts each day from each deposit sheet.

ie:
48000
80000
12000
3000

200
45000
10000

And so on. I have posted an example spreadsheet if needed. (The portion is green is all that needs to be summed but keep in mind it changes amount of rows included changes each day, and the yellow is where the solution goes, but I can easily change that). There are other formulas needed but I have figured those out. I need to run this macro daily just for the last group.

View 6 Replies View Related

Set Range Of Row To A Variable?

Mar 14, 2012

I have a problem of setting a range of row that might expand regularly.

I tried a simple method but...

Code:

' Count the used range row
Dim count As Integer
Dim usedrow As String
count = ActiveSheet.UsedRange.Rows.count
usedrow = "C" & count
' The items are in A1:A105
Set AllCells = Range("C4:usedrow")

View 2 Replies View Related

Range As Variable

Mar 7, 2008

I left my Excel books at home, so I can't even look up the answer, and it's incredibly frustrating, since I know it's something small that I'm missing.

I've got a code that I want to cycle thru 12 ranges, named "Retrieve1" thru "Retrieve12". This is the snippet of code that I'm having the issue with is:

For I = 1 To X
NextRange = "Retrieval" & I
Range(NextRange).Select
Application.Run Macro:="EssMenuRetrieve"
Next I

I only made the "NextRange" variable because I originally had "Retrieval" & I in the range select statement and it didn't work.

View 9 Replies View Related

Range Variable ...

Dec 9, 2008

I am using this coding

LR = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row

Range("A" & Row.counts & ":" & "D" & Rows.Count).Copy Destination:=Sheets("Sheet2").Range("A" & LR + 1)
And it keeps giving me the error "Object required"

I am trying to copy from A-D and the row is a variable to which row was checkmarked at that time.

View 9 Replies View Related

Sum Of Variable Range

Nov 6, 2006

I am trying to create a spreadsheet that will predict the quantity of a product sold in a given month based on the number of new clients that month and the frequency with which the existing clients will need that product to be replaced. E.g. Washing Up Liquid is required by every new client and they will need a new one each month. Toilet Cleaner is required by every new client and they will need a new one every 3 months.

I have 'hard coded' the two examples into the formula on the "Non-Variable" sheet. However the Frequency of Replacement is speculation; it may traspire that a bottle of Toilet Cleaner only lasts 2 months, in which case I would have to go into each cell and change the formula to reflect this. I believe Add or SUM Every nth Cell may hold the answer but I am failing to get it to work with my data due to being a novice and not really understanding the formulae used! The second sheet is my attempt.

As you can see, it counts 3 months forward from the first month, not 3 months BACK from the CURRENT month. It also simply doesn't work: Washing Up Liquid should equal 285. Ideally I would like to keep the format of the 1st sheet as this matches the rest of the the workbook (not included).

View 4 Replies View Related

Set Variable To End Of Range

Dec 23, 2006

still trying to figure it out how the logic in VBA works

'this selects a block of sells and put them in variable rormu. Right?
Set test = ActiveSheet. Range("i65535").End(xlUp).Offset(-1, -3)
Set test2 = ActiveSheet.Range("i65535").End(xlUp)
Set formu = Range(test, test2)

'here i try to create another variable for a range after last used row
Set newg = ActiveSheet.Range("f65535").End(xlUp).Offset(2, 0)
Set newg2 = ActiveSheet.Range("f65535").End(xlUp).Offset(3, 3)
Set pst = Range(newg, newg2)

View 6 Replies View Related

Set Variable Range

Mar 8, 2007

I have reached a point in my code where I have a variable range selected. I want to autofill the selected range of data to a new range.

My code is:

Range(Cells(7, LastReportColumn - 1), Cells(LastReportRow, LastReportColumn - 1)).Select
Set DestinationRange = Range(Cells(7, ReqMonths + 5), Cells(LastReportRow, ReqMonths + 5))
Selection.AutoFill Destination:=(DestinationRange), Type:=xlFillDefault

The select part works. However on the second line (set DestinationRange) I get a type missmatch.

View 5 Replies View Related

Set Range As Variable

May 1, 2007

I searched and I seached but I cant find the answer. I want to paste a set of cells in a blank range that is next to data already in the workbook. I cant get the right wording for the variables in the range I want to paste to. Here is what I got so far, the red text is what I am getting hung up on. (ya I know it sucks)

Dim mycel1 As Range
Dim mycel2 As Range
Set mycel1 = Range("A1").End(xlToRight).End(xlDown).Offset(0, 6)
Set mycel2 = Range("A2").End(xlToRight).Offset(0, 1)

Range("N2").select
Selection.Copy
Range(mycel1, mycel2).Paste

View 5 Replies View Related

Variable For Range

Aug 16, 2007

Dim varAAR As Variant
varAAR = Range(Selection, Selection.End(xlToRight)).Select
. Range(Selection, Selection.End(xlDown)).Select

But the way I understand it, varAAR will only equal the first line, I want it to be the range that is selected from both lines.

View 5 Replies View Related







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