Check one series value, change corresponding point colour in 2nd series - vba

I have an automated pareto chart working well in Excel.
I want to change it to check if points in the cumulative percentage series have a value of less than 80% and colour the same number point in the count series if this is the case.
Tried this; doesn't throw any errors but also doesn't work.
I think it should be iterating through a list of values, checking if they are <80 then updating the point at the corresponding i in the count series.
Set percVals = paretoChart.Chart.SeriesCollection(percentSeries).Values
For Each i in percVals
If percVals(i) = <80 Then
With paretoChart.Chart.SeriesCollection(countSeries).Points(i)
.Format.Fill.ForeColor.RGB = RGB(0,0,225)
.Format.Line.ForeColor.RGB = RGB(0,0,225)
End With
End If
Next i
The "paretoChart" variable is set earlier in the code and is working fine throughout.
I've tried without the 'with' statement. No difference.
There is a similar question comparing the two values across series, but I don't think I can adapt that to work here. Any ideas appreciated!

Related

Openpyxl How does one define print area from a variable or other input like max rows?

I am very new to python in general but have a set of code where I am needing to define the print area for multiple excel files. My code is built to step through thousands of files in a directory and they are all relatively similar but vary in row length.
I am trying to do something akin to:
worksheet.print_area = "['A1' : 'F' + str(max_rows)]"
The code above is not working because it is not a valid coordinate range because I am guessing the print.area function is requiring an exact range like [A1:F45]. But I am needing that last number to be able to change depending on the max rows within the sheet.
Any and all help is appreciated.

IF statement error despite the check being FALSE and the [value_if_false] being 0 or 1

For my own amusement I am trying to automate a project from work to learn more about excel vba. For the primary tab of data, I have an import function that drags in the relevant columns from another sheet for columns A through J. After that, there are a bunch of columns already set up to manipulate the the data being imported.
One of the calculation columns is supposed to return a basic 0/1 flag if the related company has been a client for >20 years. However, it ended up being a very slow UDF, so I wrapped it in an If statement to check if any other flags are false first so I can skip the slow calculation if the claim is already being eliminated. It worked fine before I went back to tweaking the import macro. Here is the function:
=IF( Q2*O2*N2 = 0, 0, IF(CompanyYears(J2, End_of_Claim_Period, Analysis_Width) >= Valid_Co_Years, 1, 0))
So now after the data import the only two results the column gives are 0 and #VALUE!. However, the 'evaluate function' step through confused me more. Turns out that for every value error, the 3 flags from columns Q/O/N are 1. So first the evaluate looks up and multiplies those 3 flags, gets 1=0 -> FALSE. The next thing it does is resolve what the named range End_of_Claim_Period points to. While it successfully changes it to a cell address, the outer IF statement's value_if_true changes from 0 to #N/A at the same time. The inner if statement continues just fine to a result of 0 or 1, and finally the statement
=IF(FALSE, #N/A, 1)
or
=IF(FALSE, #N/A, 0)
gets evaluated to #VALUE!.
Also, if I try to filter that column to see only the rows with a #VALUE! response, it correctly reevaluates them to the appropriate 0/1 values. I tried having the vba code filter then unfilter the row automatically but that leaves the errors in place still.
Update: While working on something else I came across a somewhat similar question here:
Excel is not updating cells, options > formula > workbook calculation set to automatic
I added Application.CalculateFull in at the end of the macro, which technically solved my problem, albeit for a notable performance hit.

Changing graph range based on specific cell data

See image for what I have going on
So the red column will at some point, which is different every day, change from 20 to 50. The start cell up top uses that lookup formula to find when this is. So for this example it is 10/11/16 14:37. I want to graph the green and blue columns, starting at that cell time and ending at the end time (which is just a max() of the times to get the end time).
I've looked into offset and name manager but I am really confused on those. Either using VBA or something else to change the graph (on a different sheet) to start at whatever that start time is would be awesome.
You can try the following:
In the column AL set, in each cell, the value to be defined by the following formula
AL1 = IF(AI1<50,0,1)
AL2 and following = IF(AL1=1,1,IF(AI2<50,0,1))
Then define each AM to be AL*AK, and plot AM.

VB.NET CHART- Display a subset of the total data points

VB 2008
.NET FRAMEWORK 3.5
MSCHART - FASTLINE CHART TYPE
Is it possible to have an MS Chart control contain 20,000 data points, but only show the last 100?
I know that I can select the last 100 from my datatable and use it as a datasource.
Chart1.DataSource = cMs2.dsData.Tables("readings").Select(wFilter, wSort).Take(100)
That's not what I want.
I know that I can populate an array or collection with the last 100 data points and use it as a data source.
Chart1.Series("readings").Points.DataBindXY(colCtr, colReadings)
That's not what I want.
I need to do 1 of 2 things:
Manually add data points and be able to show only the last 100 or last 1000 of them that just came in. This must be done without re-populating the chart. Just show a portion of the complete set of data points.
wSample = wSample + 1
Chart1.Series("readings").Points.AddXY(wSample, wReading)
Chart1.Series("readings").SHOWONLYTHELAST100DATAPOINTSWITHOUTCLEARING
Initialize a chart with a certain number of the total readings with a databind, then manually add new data points one at a time while removing the oldest data point. For example, initialize the chart with 100 data points, then add a new data point, remove the first data point, getting us back to 100. (I'm successfully doing this one, except the chart doesn't behave like I expect. The chart grows, remaining blank/empty where the 'removed' data points were. I do chart.update but it doesn't refresh it.) Note that I am allowed to take more time to initialize the chart (clear/populate), I don't have that time to do it as each new data point comes in.
wSample = wSample + 1
Chart1.Series("readings").Points.AddXY(wSample, wReading)
If Chart1.Series("readings").Points.Count > 100 Then
Chart1.Series("readings").Points.RemoveAt(0)
Chart1.Update()
End If
NOTE: Doing a process that causes me to have to clear and rebind the data to handle the addition of a single data point causes me problems because it takes too long. I'm just looking for the quickest, most efficient way to handle this. Thank you for taking the time to read this...!
You can manually set the Minimum and Maximum values of each axis by modifying the .Minimum and .Maximum values of the axes like
Chart1.ChartAreas(0).AxisX.Minimum = 100 'Example value
Chart1.ChartAreas(0).AxisX.Minimum = 200 'Example value
As discussed in the comments to your question you can either use your method #2 (add datapoint and delete datapoint index 0 and then select the new minimum and maximum X-Value from the series with LinQ:
Chart1.ChartAreas(0).AxisX.Minimum = (From p As DataVisualization.Charting.DataPoint In Chart1.Series(0).Points Select p.XValue).Min
Chart1.ChartAreas(0).AxisX.Maximum = (From p As DataVisualization.Charting.DataPoint In Chart1.Series(0).Points Select p.XValue).Max
or you can, as you have now done, just set the minimum value to a X-value some points before the last point.

working with arrays

Ok I am not completing understand this. I am suppose to only Find the total of each column in the last row. Find the grand total in the last cell (the bottom right corner)
Ok i have tried to do the grandtotal but i am not getting what she wants done I have also tried to reverse the arrays but that was wrong to. I am only suppose to add two line one line is find the total of each colums in the last row and to find the grandtotal. Can someone please explain to me what i am doing wrong thank you.
Module Module1
Sub Main()
Dim sum(5, 4) As Integer
Dim row, col As Integer
Dim grandtotal As Integer
For row = 0 To 4
For col = 0 To 3
sum(row, col) = row + col
sum(row, 4) += row + col
Next col
Next row
For row = 0 To 5
For col = 0 To 4
Console.Write(sum(row, col) & vbTab)
Next col
Console.WriteLine()
Next row
End Sub
End Module
It looks like you have a pretty good grasp of the code you need to use, but I think the main issue here is that you're getting a bit confused with what you actually want the code to do. I too am having a hard time deciding what your actual goal here is, as you say one thing but then have code for something slightly different. I'm assuming this is a homework assignment, so I'm not going to give you the code (especially since I'm not 100% sure what code you might need), but I'm more than happy to go through this stepwise as clearly as I can, and hopefully we'll get to the bottom of your confusion.
To clarify your requirements:
You say you're supposed to find the total of each column, and place that total in the last row. According to your code, that would be row 5 (actually the 6th row).
You then say you need the grand total in the last cell, the bottom-right corner. Since you have 5 columns (0-4), that would be a total of the first 4 columns of row 5.
If we imagine the 2D sum array as a matrix, the problem as stated should yield the following:
Desired Matrix http://dl.dropbox.com/u/1497850/Hosted%20Images%20for%20Websites/MatrixDesired.jpg
Where the "x's" are blank (technically 0), since that column is reserved as the "grand total" column (only the bottom-right should be filled in). For reference, this array/matrix will have the following coordinates:
Coordinate Matrix http://dl.dropbox.com/u/1497850/Hosted%20Images%20for%20Websites/MatrixCoords.jpg
However, as you currently have it coded, your sum array will look like this:
Actual Matrix http://dl.dropbox.com/u/1497850/Hosted%20Images%20for%20Websites/MatrixActual.jpg
What you've done in your code is made the final column the "total column" and ignored the final row. In this case, the bottom-right cell would still be the grand total, but you'd be summing the numbers in column 4 rather than in row 5. This goes against what you stated you want to happen, but is pretty easy to correct (especially now that you can see what's actually happening compared to what you want to happen).
However, maybe this is what you actually meant to happen, and you just misphrased the question a bit? (Or maybe this is what you meant by saying you tried to reverse the arrays?) The point is, rows and columns in even semi-large arrays/matrices are generally easily transposed, so it's important to make sure you're using the right terminology at all times.
Edit: Sorry, I misread your second For loop when I first answered, I apologize. I see now that you're printing the sum array out, but your problem was still probably due to the fact that you weren't filling in the array as you expected. Once you fill the array the way you actually want, your printing statement should work just fine.