How to use Conditionally Formatted Data bars on three leveled grouped rows that are populated with data on the fly - excel

I have a situation where there are rows grouped at three levels. The data is populated dynamically. Currently, I am able to assign conditionally formatted data bars across the whole column (Col Q). But, I want different colored data bars for each level of rows. See in the picture below, I want data bars for all red colored rows to be in red color (Row 47), data bars for purple colored rows to be in purple color. What I have right now is purple all the way.
* UPDATE *
This is the code block I have for all the red rows. Somehow, the bar size is not reflective of the value present in the corresponding cell.
Set db = Worksheets("Deliverable-Epic-Story Progress").Cells(delvRow, delv_StatusCell + 1).FormatConditions.AddDatabar()
db.BarColor.Color = vbRed
db.MinPoint.Modify newtype:=xlConditionValuePercent, newvalue:=0
db.MaxPoint.Modify newtype:=xlConditionValuePercent, newvalue:=100

Modified the code block to this. I added the format via code. Changed the min and max values.
Cells(delvRow, delv_StatusCell + 1).NumberFormat = "0%"
Set db = Worksheets("Deliverable-Epic-Story Progress").Cells(delvRow, delv_StatusCell + 1).FormatConditions.AddDatabar()
db.BarColor.Color = vbRed
db.MinPoint.Modify newtype:=xlConditionValuenumber, newvalue:=0
db.MaxPoint.Modify newtype:=xlConditionValuenumber, newvalue:=1

Related

How can i change different colors between 5 categories when I use pd.qcut(df, 5) in a chart. f example: first 3 row = red, next 2 rows is blue,

here is the image of the code, someone suggest at I patch for each bin and use color mapping but I dont know how to do it

How to avoid "A Chart may only have up to 256 series" issue (Excel VBA)

I'm trying to build bubble chart from a scratch in excel. Below is piece of code I'm using. Everything works fine until SeriesCollection.NewSeries reaches 256. Then I'm getting error message: A Chart may only have up to 256 series.
Can you anybody help me, how to avoid this issue. Is there any more elegant solution? Thanks a lot for any of your hint or advice.
Source code for my bubble chart:
With wsAnalytics.ChartObjects.Add(Left:=0, Width:=995, Top:=0, Height:=580)
For i = 1 To Range("Config_BubbleChartData").Rows.Count
.Chart.SeriesCollection.NewSeries
.Chart.SeriesCollection(i).name = Range("Config_BubbleChartData").Rows(i).Cells(1, 1)
.Chart.SeriesCollection(i).XValues = Range("Config_BubbleChartData").Rows(i).Cells(1, 3)
.Chart.SeriesCollection(i).Values = Range("Config_BubbleChartData").Rows(i).Cells(1, 4)
Select Case BubbleColor
Case 1
.Chart.SeriesCollection(i).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
Case 2
.Chart.SeriesCollection(i).Format.Fill.ForeColor.RGB = RGB(0, 0, 255)
Case 3
.Chart.SeriesCollection(i).Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
End Select
If i = 1 Then .Chart.ChartType = xlBubble3DEffect
.Chart.SeriesCollection(i).BubbleSizes = "=" & Range("Config_BubbleChartData").Parent.name _
& "!" & Range("Config_BubbleChartData").Rows(i).Cells(1, 5).Address(1, 1, xlR1C1)
Next i
You only need as many series as you have colors. Certainly you don't need more than 255 colors, since no human would be able to distinguish more than a dozen in a cluttered bubble chart.
Set up the data with four columns for X, Y, bubble size, and bubble color. Append another column for each color in the bubble color column, and use the color name as the column header. Use an IF formula in these columns to put the Y value for each color into the appropriate column.
In my example, I have X and Y in columns A and B, bubble size and color in C and D, plus the bubble color names in E1:G1. The formula in cell E2 is
=IF($D2=E$1,$B2,NA())
and I've filled this into E2:G16. The result is the Y value if the column header matches the color, and #N/A otherwise, which will not plot.
Select A2:C19 and create the bubble chart (top left chart).
Click the Select Data button on the Chart Tools > Design tab of the ribbon, select the only series in the chart, and Edit it, so cell E1 is used for the name, and E2:E16 is used for the Y values. Keep A2:A16 as the X values and C2:C16 as the bubble size. This series will have the default color for the first series, which in Excel 2013 and 2016 is blue (top right chart).
Stay in or return to the Edit Data dialog, and add a series. Use cell F1 for series name, A2:A16 as X values, F2:F16 as Y values, and C2:C16 as the bubble size. This series will use the default second color, orange (bottom left chart).
Add one more series, use cell G1 for series name, A2:A16 as X values, G2:G16 as Y values, and C2:C16 as the bubble size. This series uses the default third color, gray (bottom right chart).
Note that all series use the same X values and bubble sizes, but different Y values.

How to Set the Background Color of a Cell in a MigraDoc Table

I have a MigraDoc table where I specify a row height of 0.75cm, and the text is vertically-aligned in the middle of the cell. When I set cell.Format.Shading.Color to something non-white, there is still a portion of the cell near the border that is shown as white around all four sides.
I discovered I can remove the white section to the left and right of the text by setting column.LeftPadding = 0 and column.RightPadding = 0. However, I cannot figure out how to get the white stripes at the top/bottom of the text to disappear without affecting the vertical alignment of the text. If I change the paragraph line height to 0.75cm, the stripes disappear, but the text is then bottom-aligned within the cell. I cannot set the column shading color because each cell in the column contains a different color. Does anyone know a way to force the paragraph to fill the cell vertically (or otherwise get the background color to be uniform within the cell)?
Here is a sample of my code (in C#) where table is of type MigraDoc.DocumentObjectModel.Tables.Table:
...
// Add a column at index #2
var column = table.AddColumn();
column.LeftPadding = 0;
column.RightPadding = 0;
// Add more columns
...
// Iterate through the data printed in each row
foreach (var rowData in myData)
{
// Create a row for the data
var row = table.AddRow();
row.Height = ".75cm";
row.Format.Font.Size = 11;
row.VerticalAlignment = VerticalAlignment.Center;
...
// The following is for illustrative purposes... the actual
// colors and text is determined by the data within the cell
var cell = row.Cells[2];
cell.Format.Shading.Color = Colors.Black;
cell.Format.Font.Color = Colors.White;
var paragraph = cell.AddParagraph("Example");
...
}
Try cell.Shading.Color instead of cell.Format.Shading.Color - the former sets the colour of the cell, the latter sets the colour of the text background (and the padding of the cell will then have a different colour).

Retrieve top 10 results from a data set by category

The data set I have is for example and the actual data will have upwards of 100 people. I need to retrieve the top 10 scores from each category in the picture below:
I think the answer is really quite simple.
In each of the corresponding cells, use the "large" forumla.
In cell for vertical 1 it would read large(column vertical, 1) - Returning the largest value in the set.
In cell for vertical 2 it would reage large(colum vertical, 2) - Returning the 2nd largest value in the set.

Keep Chart Data Label from Wraping

I have a project where I have to put user generated data labels in a chart. These need to be on a series line as such:
![What I want format][1]
However in some instances the text wraps. How do I keep the text from wrapping in excel 10? see below
![enter image description here][2]
'-------- FORMAT DATA LABELS -------------------------------------
ActiveSheet.ChartObjects("OperBal2Takt").Activate
h = 0
For h = 2 To 7
With ActiveChart.SeriesCollection(h).Points(1)
.HasDataLabel = True
.DataLabel.Text = Cells(2018 + h, 8).Value
'.DataLabel.Width = msofit
End With
Next h
In Excel 2013, the size of your data label can be changed. In previous versions, the label cannot be resized.
In earlier Excel versions, sometimes I've stretched the chart to make it wider, but shrunk the plot area of the chart down to the original size, so the white space is wider on both sides of the chart. This works because the maximum size of a label is proportional to the chart width.
Other times I've replaced the data label with a text box, which can be flexibly resized.
use this code:
ChartObj.chart.seriescollection(1).datalabels.Format.TextFrame2.WordWrap = msoFalse
and also, but less usefull:
ChartObj.chart.seriescollection(1).datalabels.Format.TextFrame2.AutoSize = msoAutoSizeNone

Resources