Color a specific range of cells in the same row - vba

Similar to a Gantt Chart but not quite the same, I'm trying to color a variable range of cells on the same row.
As you can see I have a variable number of tasks and a variable start and end for each task
I've created a simple time series where the "Machine 1", which is in the row number 6, is making all the tasks. The time series is in the row number 3.
So basically, I need to color the ranges given by the tasks table in the Machine 1 row, using that time series as a reference to start coloring the cells. Each task has to have a different color.
As I'm a beginner in VBA, I've been trying to do this using a formula:
=IF(AND($C4<=AK$3;$D4>=AK$3);1;0)
Being C4 the start of the task, AK3 the place of the time series right now, and D4 the end of the task. Then I would fill the whole Machine 1 row. This would give a 1 in the range of the task and a 0 before and after the task, then I could format the row and color the cell by the given value in each cell. (1 color and 0 blank)
The problem is that this only works for one task and I really don't know how to change the formula to add the other tasks. I'm pretty sure this can be done in VBA but, like I said, I'm still a beginner. Please help me
The final answer should look like this. The color doesn't matter, it's how to color the variable ranges automatically the problem

If I understand what you want correctly, this can be done with conditional formatting:
Use four conditions, one for each of the following formulas:
=COLUMN(AK6)<=$D$7+37
=COLUMN(AK6)<=$D$6+37
=COLUMN(AK6)<=$D$5+37
=COLUMN(AK6)<=$D$4+37
and apply them in that order to $AK$6:$BZ$6

Related

Conditional formatting 1 cell based on cell input on another sheet, apply to entire row

For work I need to create a resource management excel file. My goal is to create an overview as is seen here:
If John would have taken a few hours off, or if he has a fey hours of sick leave, I would like to turn this cell only to change colour so I know that John will be absent for whatever reason on this day.
However, since I'm creating this for an entire row (for a whole year), I do not want to create conditional formatting per cell because that would be plain madness.
Here is an example per employee (in this example John):
enter image description here
So what I need is a formula to check if a cell in a row (for example sick leave) on the employee worksheet is grater than 0 and then change the colour of only the corresponding cell on the recourse planning worksheet, not the entire row.
Does any of you guys know if this is possible in excel 2016? Preferably without VBA scripting since I have to transfer this excel file to a co-worker who is not into VBA programming.
Thank in advance.
Nuntius transmittendus!
This is definitely possible without any code. Use CountIf() as tinus087 commented. The tricky part is how to create the address range used by the CountIf() so that you can put one conditional format on all the cells. On the the one hand you need the column of the cells being checked to match the column of your total cell. On the other hand the worksheet tab name needs to change depending on which row you are on. So use INDIRECT() to point to the correct worksheet and OFFSET() to look at the correct cells.
So, for cell C4, the formula you want to use as the range in your CountIf() is OFFSET(INDIRECT($A4&"!A1"),3,COLUMN(C1)-1,4). When applied to cell C4 this creates address John!C4:C7. When used for cell D4, it results in John!D4:D7.
You'll probably want some error checking to deal with the #REF! error happens when the formula is applied to a row without a first name or where the name listed doesn't match any worksheet tabs.
Something else to think about, if you haven't already, what happens if there are two John's? Is the 2nd John going to be named John2?

Conditional cell formatting on SSRS pivot table

I created a pivot table in SQL that has report names along the left side, and hours (00:00, 00:01, etc.) along the top. The values in the table are the number of times each report has been used during that hour over the past three months. I've imported the table into SSRS, and I'm trying to create a heat map of sorts. I want to color the cells darker or lighter across the row based on the number in each cell compared to the value of cells across the row (cell that has the highest value will be the darkest colored).
I've tried following this guide to color the cells, but here the entire row is one field, while I have separate fields for each column. Is there a way to achieve this?
EDIT: Added picture of table design, and preview where coloring is done incorrectly
I understand your problem better now...The function uses the min and max values of a column to determine the range from lightest to darkest, then it probably looks at what fraction of the range your actual value is. In your case where you have each column's data coming from a different cell it'll be a pain unless your columns are fixed and even then it's more trouble than it needs to be.
I would suggest the following.
DON'T PIVOT your data in SQL, we can do that really easily in SSRS, your dataset will be simpler too something like
ReportName Hour UsageCount
ReportA 0 8
ReportA 1 4
ReportC 22 18
and so on...
Create a new report and add a matrix with reportName as the row group and hour as the column group. The data values will be UsageCount.
That's it for the report design, then just set the cells back ground based on your function but this time you can pass in Max(Fields!UsageCount.Value) etc as per the sample.
I've rushed this a bit so it if not clear, let me know and I'll post a clearer solution.

How to color a cell based on values and date difference in another cell using VBA

Consider I have a Table A in Excel - details as below:
And another Table B as follows
I want out-put as follows,
The Name from Table B has to be checked with Name in Table A, and respective StartDate and EndDate should be picked from Table A and same should be compared with dates in Table B and cell under that name should be colored to green if Status in Table A is in "In Progress" or to Red if in "On hold"
For Example:
Consider Jack in Table B, it has 3 records in Table A, The first start date should be picked i.e 4-Apr-2017 and End date as 27-Apr-2017, and respective coloring has to be done based on status field.
How can I achieve this using VBA/anything in Excel. I'm new to VBA.
Yes you can do it in VBA but I would recommend using conditional formatting (formula) as it doesn't require programming knowledge. To do this, you will need to employ the Vlookup formula.
I believe the output you want is something in the picture link here?
To make conditional formatting, look in the "Home" tab, under Styles -> Conditional Formatting. Highlight the cell you want to format, then select Conditional Formatting -> New Rule. This will cause a new window to pop up. Select "Use a formula to determine which cells to format".
You would want 2 conditional formats.
1.To show green if the date is within the start and end date. To do so, select the first cell in the Gantt chart (cell B8 in example) then enter formula below.
=IF(AND(B$7>=VLOOKUP($A8,$A$2:$D$5,3,FALSE()),B$7<=VLOOKUP($A8,$A$2:$D$5,4,FALSE())),TRUE(),FALSE())
2.To show red when user has item beyond due date, enter formula below with same cell highlighted.
=IF(B$7>VLOOKUP($A8,$A$2:$D$5,4,FALSE()),TRUE(),FALSE())
Once that is done, you can apply the format painter or copy and paste the cell with conditional formatting to extend your table/Gantt chart.
Note that the $ signs are important as they lock the relative reference positions in the formulas. Using the second formula as an example, B$7 refers to the date and you need the reference to be locked to row 7, where all the dates are. On the other hand, the column reference (Column B) can be shifted as you want it to change to with the columns to properly compare against the other dates.
As for multiple items per user, can you expand upon your initial question? Would you like to track based on per user or per item? I am assuming that you're creating a Gantt chart to track a project. In that case, it would make more sense to track specific tasks assigned to people. You can modify the example given to track based on task.

Grouping and colouring each grouping in excel 2013

can you tell me how I can group rows using a value in a specific cell and then highlight the individual groups by alternate colours i.e. one group with white background and one group with a colour in excel? I have macro code which inserts a blank line but I don't know how to colour using macro.
You don't need a macro, just run conditional formatting for values equal to the value of the group you are using.
Here is an excellent guide for how to highlight a row using conditional formatting. It does exactly what you asked for without having to write any code. As you can see it works for multiple rows sharing the common set value.
This is assuming that the only reason you wanted them grouped in the first place was for colouring them together, this method is best if you want to preserve the order of your data.

Writing a VBA makro to sum a nested bill of materials

Hi I have looked around extensively on the web but have not been able to find a way to calculate a nested table of totals.
My data is pictured below.
What I am looking for is a way to add up all of the sub items of an item and put that total in the cost of the original item.
so for instance the total of line 6 will be the sum of lines 7,8,9, and 10. but the total of line 2 will be the totals of lines 5,6,11, and 12 each of which needs to be seperatly subtotalled.
I have tried excels subtotal function, but it is clumsy and not a generalised solution. I may need to add or subtract components over time and have the totals calculated again.
I have tried a few if then and for loop combinations, as well as an attempt at a function that calls itsself, with very limited success.
I think I have a block in how to approach this, as well as some programming knowledge gaps, like can a function call its self, and if it does, will it automatically create an independant set of function instance variables, or will the new call overwrite the old instances variables.
Any help with methodology and knowledge would be great.
Thanks
Does this formula work for you? In a new column, say E, starting in E3 and copied down:
=SUM(IF(LEFT(B3:B$999,LEN(B3))=B3,D3:D$999,0))
Here 999 is a dummy last row --- change it to suit your situation.
Columns B and D are assumed to hold Outline and Bom Cost, respectively. The logic is: sum up all rows below (and including) the current row if and only if Outline starts like the current row's Outline. So if Outline in the current row is 1.2.3 it sums up all Bom Costs found below where Outline start with 1.2.3 (1.2.3.1, 1.2.3.2, 1.2.3.2.1, etc.).
This formula assumes that the outline is properly ordered.
It is also assumed that the Outline values are text. If they are not, the formula above will fail when Outline is a whole number (1, 2, ...). This longer formula converts whole numbers to text and should work:
=SUM(IF(LEFT(B3:B$999,LEN(B3))=IF(LEN(SUBSTITUTE(B3,".",""))<LEN(B3),B3,TEXT(B3,"0")),D3:D$999,0))
Hope this helps.