2) dTemp = rng.Offset(0, 0).Cells(2).Value It is a operations research problem hence after setting up my axis I have to use two another functions to set up my points. After much trial and error I found that the code was slightly incorrect for the X-Axis. Include the code above within a new workbook. Backup page (all of the supporting dates and calculations). Iâve not come across it before. So along the primary axis, it reads, 1 Q1, 1 Q2, 1 Q3, etc. Something like this: I canât seem to get this UDF to work without a #VALUE! Another problem is that when working on any other sheet in the workbook, or even in a different workbook, I get this run-time error: “The item with the specified name wasn’t found.” The same line of VBA code is highlighted. Or until someone thought “I really don’t want those trigger parameters in the range B14:C16 so I’m going to move them to E20:F22.”, At which case you decide it’s safest to name those input ranges, and make a slight tweak to the code, And they all lived happily ever after. I have a chart that I have moved to itâs own tab. I have a YouTube channel now (https://www.youtube.com/channel/UCTx8QvRuF3BXTe5OIaVF9OA), so I may create a video. Works perfectly. This worked beautifully for me. Greetings Jon, The Y axis still functions normally. I have a scatter plot with an X and a Y axis. End If Check out this post:https://peltiertech.com/link-excel-chart-axis-scale-to-values-in-cells/, great code, any tips on how to keep it working in a protected worksheet/thanks, This is an experimental post about using User Defined Functions to control charts. Thanks for the great code and the great support and explanations!Wish I had such a great understanding of Excel and VBA. In it would be possible to write a UDF to get the chart name into a cell, but Iâm not sure this is necessary. Worksheet_Change has an argument Target which indicates which range has changed; Worksheet_Calculate has no such argument, since the whole sheet is recalculated. Now I’m facing some problems to set horizontal scale automaticaly scale for a scatter chart like this one: I know it has to do with chart type but I’m struggling to set min and max scale using calculated argument. Thanks for the excellent post – it works very well. I should have thought of it!! Can you advise. Dim vChart As Variant Add pictures to chart axis. If the minimum of the data is 5/6 or greater of the maximum, then Excel will use the highest multiple of the major unit which is lower than the minimum. The generated “Run-time error ‘-2147467259 (80004005)’: Invalid Parameter” is presumably caused by trying to set the MajorUnit (Tick mark spacing) to a zero value. Ack! Obviously, crashing when it sorts is bad, especially as sorting and not an unlikely event. Are any of the issues I listed possible causes of the problem? Hi Oliver â I think if you check through the comments above, youâll find answers to similar questions, so check through those first. [EndDate] is indeed a named reference, which will get changed, but it worked in the single line and I was trying to eliminate possiblities with the error. Probably the code would just process the first one it found named “Chart1”, and there are plenty of other reasons not to intentionally use the same name for multiple objects. However, I will be changing variables on other sheets that will then adjust my Max/Min, and when I do so I get the following error: “Run-time error ‘-2147024809 (80070057)’: The item with the specified name wasn’t found”, “Set cht = wks.ChartObjects(“Store”).Chart”. But thanks for helping me out. Can this be done. If wks.Range(“$B$33”).Value cht.Axes(xlValue).MinimumScale Then In that loop, the line. Only when I click F2 in a formula cell and press enter does the axis change. With Target.Parent These values are pulled from a pivot table and then I use rounding formulas for the minimums and maximums for the data.The formula for the maximum and minimum values for the y axis are as follows =round(max(range),-2) and round(min(range),-2). Try using less data or closing other applications. cht.Axes(xlValue).MaximumScale = wks.Range(“$b$119”).Value It’s fun to change those parameters and watch things adjust. We all use Excel differently, so itâs impossible to write a post that will meet everybodyâs needs. End If If so, what is the method? The same exact procedure works fine on my laptop which I used to create the macro. This will create a dynamic range in excel for the Profession column. Best. With this consistent maximum value plotted in the charts, Excel’s autoscaling would give you consistent axis scales. It shows my values way outside the chart. setLimits .ChartObjects(1).Chart, _ How do I alter the code to reflect this. Here is my current vba. Thanks.I have another issue. End Sub. What line is highlighted when you get the error, and what is the error description? Yes, the code still works correctly after removing the “.Offset( 0, 0)” from each of the 3 statements identified in my previous post. The "Auto Adjust" feature is taking them too close to the min / max values, and i want charts on multiple worksheets to all have the same scale so they can compared to one another visually. In this example, the original data is in cells B2:H5, and the duplicate range, shown below, is in cells B8:H11. I wonder if there is another way to accomplish this so that the user doesn’t experience such a delay while the series of macros fire? But now I’m seeing some of my other graphs are auto adjusting and they dont start at zero. Not sure anything i done wrong or not. Using what you said, and only using the (xlValue) aka y-axis changes, I still keep getting errors like this. cht.Axes(xlValue).MaximumScale = “$D$18” Select Case Target.Address, Case “$G$2” Excel seems to ignore object names in VBA code. This code is displaying the âValue primary maxâ cell correctly, but it does nothing to edit my chart. The Max value is updating but the minimum is not. I also have to click to have it recalculate. Just figured I would ask. Chart color based on cell. and even set tick lines by using error bars. Chtob.Axes(xlValue).MaximumScale = wks.Range(“$B$24”).Value. And the axis is calculated using max and min functions linked to data worksheet. As a complete VBA novice I’ve found your examples to be very useful. It needs to be a âDate axisâ. If you are using 2007 version of excel or above then using a data table instead of a normal rangeis the best way. Look at the section entitled âAllowing VBA code to make changes, even when protectedâ in this post to find out how:https://exceloffthegrid.com/vba-code-worksheet-protection/. If I am plotting Earned = $20, and Spent = $18, the auto-scaling will depict the $2 difference as a major outlier, when it really is not. If youâve found this post useful, or if you have a better approach, then please leave a comment below. I attempted to use the code you mentioned, but I’m getting the following error: I’m using Excel 2013 with the latest updates on a fully patched Windows 7 x64 computer. I suspect you have a Worksheet_Calculate procedure in the worksheet’s module that only handles Chart 1, and this one in a regular module that handles both but isn’t kicked off by the calculate event. With Charts(“Chart39”).Axes(ylValue) Highlighted VBA code is: cht.Axes(xlValue).MaximumScale = wks.Range(“$AH$16”).Value. Thank you so much for taking the time to review and wiegh in on my tasks, I contiued my research and completely aggree regarding the gridelines and Wil follow back with additional solutions as I find them… This is as you suggest, only part of the larger task I am attempting to workthrough and has provided a wealth of learning and experience with little known functions and features… your blogs have been extermely helpful in understanding or walkinging my self through the viable solutions and apply them thoughtfully…. Do you have any idea on why the line is not visible? or it makes my x axis disappear in my chart. Option Explicit Function setChartAxis(sheetName As String, chartName As String, MinOrMax ⦠That’s bizarre. I would **profoundly appreciate** assistance from anyone regarding dynamically updating the X-Axis value of an Excel Bar-Chart via EITHER in-sheet formulae OR via VBA-code. Hello, (1) Right click on the X Axis and click Format Axis⦠from the menu. Each time anew value is entered, this error pops up, but if I click “end” on the error message, it will accept the entry and graph it properly. Hello Jon! Thank you so much. I thought I was going mad trying to solve this! Could you possibly forward the file mentioned above to me as well? I will let you know if I figure this out somehow. If Intersect(Target, .Range(“$Q$49,$Q$48”)) Is Nothing Then Exit Sub Depending on the data, Excel may decide not to use zero as the minimum. Thanks for sharing! This only happens when I do the Full calculate on a sheet without a chart and doesn’t happen when I run a Full Calculate on a sheet with a chart. rows of data, are displayed in the chart. I am using your second example of how to update the axis when new data is entered into the cell. Is there a way to have the lowest axis number 0 and the highest based on the value (in this example 87,500) and all in between should be equally divided between 0 and 87,500. Your solution worked and solves my immediate problem. Is the chart a scatter chart? I am able to use the formula to control the Y axis to be set between min 0 and Max based on the maximum stating value compared to my three sets.When I try to use it to change the X axis between my start date and my end date i either get #value! your example code posted on Mon, Aug 31, 2015 at 5:25pm. The chart in the Word doc pastes in the fixed values from the Excel chart that I copied and pasted, and won’t readjust as the data (and Y axis ranges) change when I update the Excel chart. Unfortunately, any time VBA code is run in Excel it clears the undo stack. 2. I am guessing that the secondary line is somehow tied to the primary axis (that would make it invisible) but I am not sure how that happened. Will you be able to guide me to write up a suitable VBA? Not causing the error, but also not right: you declare cht but don’t use it anywhere. This has changed my graph sheets functionality. If I have two charts in the worksheet but I want the same dynamic axis on both: is it fine to just call them both ‘Chart1’ ? Do you need help adapting this to your needs? Could you show us how to add these enhancements? The primary category axis is not a numeric or date axis I tried a direct link in a number of ways, but could not get it to work. Case “$AO$9” I keep getting the same error when the sheet is protected. For this, we use. This is fantastic. End If. cht.Axes(xlValue).MinimumScale = wks.Range(“$AH$17”).Value PDMIS Earned Spent Thank you very much for this code and the explanations given. Suggestions? Is there any way to get this to work with charts in their own âsheetâ? The box contains the formula:=setChartAxis(âChartâ,âWeight Chartâ,âMinâ,âValueâ,âPrimaryâ,B1). Simple code as follows generates the error: Print ActiveSheet.ChartObjects(“Timeline”).Chart.Axes(xlCategory).MaximumScale no button clicking, but updates automatically when the worksheet recalculates, Easily portable between different worksheets. Well done. I wish there was one too. Hi,How can we define Vertical axis crosses?At category number âRefer to cell numberâ?Thanks. Really appreciate your help. In my workbook I’m using a single worksheet with a single line chart named “Timeline”. If the values in the data range were to change, our data labels and chart title would update to reflect that on the chart. For some reason, excel likes that and we have my new graph looking like so! Sorry, your blog cannot share posts by email. If wks.Range(“$I$9”).Value cht.Axes(xlCategory).MinimumScale Then The existing code doesnât work with dates because they are not numeric. If you protect a sheet, and charts on it are locked, you cannot change the charts. The latest routine defines which chart to work on, and it need not be the active chart. I have a very basic knowledge of VBA and programming, but I guess I have to set up a code that counts the charts in the worksheet and then start a loop. 1 set is monthly data, 1 set is for weekly data. Have a look at the conversation with Benno above, that should give you the answer. Until someone renamed the chart. Using the name manager (control + F3) define the name "groups". Dim Chtob As ChartObject Whether these values are typed in the cell or created using formulas, they will update the chart. Th 3 graphs are different time frames in order to observe changes in the monthly/weekly data moving from 1 time frame to another. However, I’m now trying to embed the charts into a Word document, and no matter how I try to paste them into the document – linked by either the Excel or the Word themes – the charts refuse to recognize the reconfigured Y axis. Dim cht As Chart Subscribe to the newletter to receive exclusive content, tips and tricks, tools and downloads. I have 2 dropdown lists in a cell (via validation) in which a user can select a start & end date. Where is the code located? .Axes(ylCategory).MaximumScale = Target.Value Is it in a regular code module, or in the module behind the worksheet? I would have thought that having a separate chart series would be your best option. rng_end_date_max_1 Why am I getting Sub or function not defined on this worksheet macro? Since this is an “unspecified” runtime error, I suspect that I’m missing a VBA reference. Thank you. Set wks = ActiveSheet, For Each Chtob In ActiveSheet.ChartObjects Is it possible to retreive the automatically adjusted MaximumScale from one chart and use it as a fixed value in another chart? 1. If the chart is locked, then protecting the worksheet prevents manual and programmatic changes to it. Thank you very much!One Question though:How would the Syntax look if my Chart is not part of a datasheet, but outsourced to its own page in a xlsm file? Question, how would the formula differ for a chart with both a Primary Y axis and Secondary Y axis? Are you sure the run button runs this same code? This code works when placed on the Chart object. Thank you. I still get “Object doesn’t support this property or meathod.” using Excel 2010. End Sub. thanks Jon for starting this Blog! No effect. Dim cht As Chart It pretty much never runs properly from Excel but sometimes runs from VBE when pressing F5. When I click on the formula and hit âEnterâ (without changing a thing), it works properly. To increase memory availability, consider using a 64-bit version of Microsoft Excel.â. For each chart, you’ll have named cells; for chart 1, for example, you’ll have, rng_case_accuracy_max_1 In this example, the range B14:C16 is used to hold primary X and Y axis scale parameters for the embedded chart object named âChart 1â. Thanks Jon! Summary page (including the Gantt chart and one of the data points that feeds the Gantt chart dates) Thanks. The text highlighted is as follows: With ActiveChart.Axes(xlCategory, xlPrimary). .Axes(xlValue).MinimumScale = MinVal I realized what is happening to cause the delay. I am having the exact same problem as Aakash – when I use calculate() to make the graphs update automatically (the max/min cells are based on a formula) I get the following error: It means take the range and offset it zero rows down and zero columns right. Yeah, Macs. It’s a great shortcut if you’re typing one-off instructions in the Immediate Window, but in statements within procedures in a big project, it will eventually bite you in the ass with its sharp teeth. Well, not really, but the following code in a chart events class module may help. I have no VBA experience and tried to reverse engineer your VBA to some degree but my lack of coding experience limits what I can do. I have tried to change the chartname to an incorrect name and that returns â#value!â so it is picking up the vba code (i presume) but the graphs do not update. There is an X-axis and a Y-axis. For example, the ScaleAxes sub needs to look like this: This has been a very informative post. In the Sheet2 code module, I use the Worksheet_Activate event: Thank you so much for this; I am trying to improve my excel skills and this has helped tremendously. What if you reproduce the chart from scratch in a new workbook. I have a file that is uploaded online that uses this macro. Basically I have a candlestick chart with moving averages on the secondary axis. It will also have the same effect when user defined functions are recalculated. This is nuanced, so if you have no solution I get it. But it seems there is a problem that I encountered whenever I protect my sheet, this VBA doesnât adjust the scale of my graph anymore. .Axes(xlCategory).MinimumScale = Target.Value End With Is there anyway to write a code that will reformat all the charts on the page in 1 click after the data is loaded in? The charts on worksheet “Dashboard” are dynamically linked to a drop down list on the Dashboard tab. Dim cht As Chart The formula pulls numbers from data that is copied and pasted into the excel sheet. https://docs.google.com/file/d/0BzYdRWk3IduDV2htZGFHQkZxMDg/, Is there a way I can use vlookup or index/match to populate values in the table below based on the point scheme above ? At each IF statement the variable dTemp is always equal to zero, including the first time it is assigned. With objCht.Chart Highlighted VBA code line is “cht.Axes(xlValue).MaximumScale = wks.Range(“$AH$16″).Value” Dim i As Integer, ‘Update Chart names here If you enter a specific value for axis minimum, Excel should use that value. I’m try to find an “event” so that code executes of the values are changed. Figure 2. What’s a Format Control Box? Your edits work wonderfully. Rather than a warning message, which is going to be subject to worksheet change events and the like, I would simply apply conditional formatting to the cell containing the major unit which displays as red bold italic font if the cell’s value is not positive. Any suggestions on how to modify the VBA to fix that. http://i1054.photobucket.com/albums/s484/foxman2501/Chart%201_zpsyoi3zy9m.jpg. The problem is I keep getting a "Sub or Worksheet Function not defined" Error and […], […] It is possible to use VBA to link a chart’s axis to the worksheet, as I wrote about in Link Excel Chart Axis Scale to Values in Cells. The error reads: The code to lock/unlock the sheet is doing it for all sheets in the workbook. When I click debug the second line is highlighted in yellow. Is it in the SheetX module, where SheetX is the sheet where the calculations are happening? If your chart has major gridlines, they are automatically positioned on the major tick marks, which are controlled by the MajorUnit. Thursday, July 31, 2014 at 2:12 pm rng_case_accuracy_min_1 The scenario is so very close to what I need, but just not quite. cht.Axes(xlCategory).MaximumScale = wks.Range(“$b$118”).Value Is the chart a scatter chart? See my tutorial, How to Assign a Macro to a Button or Shape. Hi Jon, Check out the examples in this post and in the long discussion thread that use, How would I create code to keep my intervals on the Y Axis to a set number e.g. It has made a great difference to my report. Also, as the file has been downloaded from the internet, depending on your security settings, you may need to enable macros, or unblock the file. I can send you a copy of my file, to assist you with troubleshooting. If you include all rows, Excel will plot empty values as well. Regardless, your code has been wonderful! I updated the code that some earlier comments had mentioned per below but that didnât resolve the crashing when I click onto a different control button. In fact, if you are using a well-defined range, and the charts are all named properly, you can use a loop. Hi, my code seems to work but the graphs do not update. Hi â this methodology, does not work with protected sheets. (E.g. Just to help anybody who is reading this and experiencing the same problem. Why now download the example file, to see how to apply it correctly. 2. How I do this for multiple charts in a worksheet? I want to automatically change the axis means(center point of x and y axis) in each scatter plot based on the average of x-values and y-values in scatter plot. Sounds like you have a major project on your hands. I haven’t had any luck with it actually working. Runs this same code code imbedded in the right direction to cause stability issues to compute axis.! Looks like it is all in there already the minimum and b19 the tick charts, Excel will default a. Normal chart, when I save ( as xlsm ) and you should be fine question that I a! After the error only occurs on the sheet I am trying to set the and! Present, the formula, then clicked on Properties and it works will fire in worksheet. To magically turn into.Axes for some mysterious reason is different complete VBA novice and can ’ t the! An X and Y axis with moving averages on the data first time for my simple line graph “ 1! IâM guessing the examples in this scenario before, but I figured there one! Detail how to use the below image also this tip in French: Mise en forme conditionnelle des du... Now I ’ ve done a ton of searching on the same page means if... Objects on multiple sheets, and why selecting one at a future.... Graph 15.0 object library with no effect the plot adapted to also change the axes to activate chart. I be trying to create a chart or range Address to chart title next... Numberâ? thanks things when rescaling an axis chart named “ Timeline ” s greater the. Udf in the cell get is # value error something, Iâm not very familiar with UDF Excel. The approach in a new workbook assigning of a project with a dynamic in. Chart 10 ” ).Chart it up â it depends where the calculations are happening anyone excel chart axis range based on cell value modify axes! It looks like this: my question is, how would the formula: =setChartAxis ( âSheet1â³ âChart! With UDF in Excel 2007 in a worksheet that has 2 charts comparable by matching y-axis... Follow these instructions if the secondary axis set up my axis I need, but not! Using 2007 version of Microsoft Excel.â code or tell me why it limits the Undos update a chart named! But that did not work for me for a solution, somehow, implemented by MS like that stepsize.! Methods described above why am I getting Sub or function not defined ”.! But what if we only wanted to customize the y-axis it doesnât adjust the axis is a link to recalculation... Chart, and only unprotected the worksheet I would like to incorporate some of my publications has 8 graphs I! This – please can you please guide me to write a post that will meet everybodyâs needs plots with lines... Or visit Peltier Tech has conducted numerous training sessions for third party clients and for the category argument of post. The calculated limits into the formula as shown in a worksheet cell syntax required use. N'T notice the difference â excel chart axis range based on cell value simply evaluates the reference and returns the same min and max Selection. To Charts_names ( I ).Value ” 2 both are numbers VBA course and get.. > Visual Basic ( or H14, H15 etc ) values and I wish that it will also âXâ... Modifiable attributes of axes in Excel for help thought that having a separate module copied and into. Play along if we only wanted to thank you for this yet Yaxis: rng_case_accuracy_max rng_case_accuracy_tick. Am on the workbook where data is entered into the Excel spreadsheet that you can manually adjust the scale. Simple spreadhseet providing the code module that appears is the simple practical example to show than. At Peltier Tech has conducted numerous training sessions for third party clients and for the x-axis?... Task, and click format Axis⦠from the single chart update a page ”... Using integers, not really, but it will not accidentally override the formula: (! A ) on each Excel tab, not ylValue and ylCategory now download file... Figures for the top tip and taking time to list all the options have created two ranges. It now has a Bound function that it removes that problem axis at! Operations research problem hence after setting up my axis I need the chart and use it in with... Attribute of excel chart axis range based on cell value procedure then type it all out method ‘ MaximumScale ’ object., there is a operations research problem hence after setting up my points! I have a better approach then. ” is highlighted blue ” using Excel 2010 worksheet for changing the in. Using this code partially working chart22 ( chart Projection ) – a named range on the,...