How to color a cell based on values and date difference in another cell using VBA - 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.

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?

How to reference a specific cell location within a changing table

I am not sure how, if at all, this can be done. Basically I have a report that is generated from SalesForce for some co-workers. It exports to Excel in this nice little table. Depending on their team, they filter the results and then filter the month (fiscal year in this case).
What I want to do is have text populate at the top which is based on the text that is in the first cell in the column C (not including header row of course) when they filter. How do I go about referencing the spot where C4 is currently when they select Team "White-1" and Fiscal Year "Aug"? That cell will become hidden and I will need to pull the data from C6 which HAPPENS to be in the location that C4 was just in before being hidden.
Here is an image of the report in Excel as well as the "location" that I want to reference no matter the filtering that the employee does:
Report
I assume VBA will be needed. Preferably I want to generate the text in A1
If you are ok with adding a "Helper Column" you can do the following to get the results you are wanting:
Add a column between B and C Give it a header of some kind I used "Helper". Then in this new Column use use the formula =Row() to generate a number for each row.
You can hide this column now if you want.
Then in whichever cell you want the answer you seek enter the following formula:
=Vlookup(Aggregate(5,5,C:C),C:D,2,false)
Now you can filter all you want and you should get the result you wanted.

Excel add up values in one cell based on mutliple results from one look up value

hope you are all doing well today! I've been working on a spreadsheet that tracks invoices and the hours recorded for each one. Each invoice has multiple entries with different numbers of hours for each entry, all with the same reference number which combines the project number and the invoice number. For example, for Invoice #1 of project CZ23, the reference number would be CZ23-1. Invoice 2 would be CZ23-2, and so on. This is located in Column I, while the hours are located in Column H in a sheet named "Document Data".
Now I have another sheet that tracks the hours called "Summary". What I want to do is have cell B28 of "Summary" add up all the hours from CZ23-1 from "Document Data". Since I barely know any VBA, I don't have code but I'll display the situation here:
In this case, cell B28 on "Summary" would be 15 (all the CZ23-1 hours added up: 2+5+1+7), while B29 would be 7 (all the CZ23-2 hours added up: 4+3) and so on. It doesn't necessarily have to be B28/B29, but just as a reference I've used those cells. Thank you so much for your time - hope I was able to explain everything well.
Best way to do this would be to create a pivot table.
1. Select a cell inside your data and then on the insert tab select pivotTable.
2. A "Create PivotTable" box will pop-up. Verify that your data is captured in the Table/Range. Also, you can choose if you want to have the table appear on a new sheet or the existing sheet.
3A. In the "PivotTable Fields" box, you can drag "Reference" to the Rows box and then drag "Hours" to the Values box. This should default to Sum and should add up all the Hours by Reference.
3B. Occasionally the Values box will default to Count. To change this to SUM, you can select cell B4 or B5 (See Below). Right click and select Value Field Settings. When the "Value Field Settings" box pops-up, you can select Sum on the "Summarize Values By" tab.
It sounds like you want the sql concept of 'group by' on column 'Reference'
In excel you can do this by using pivot tables
You will find pivot tables in the toolbar at Insert-->Tables-->PivotTable

VBA msgbox duplicate value base on 2 columns

I'm trying to get a msgbox when a value is duplicate base on 2 columns. The first column Value can be repeated but the second column will determine if it's a duplicate or not.
i.e.
Column B = Code,
Column L = Month
The user can enter the Code several times, but if he enters it on the same month I want the msgbox pop up
Is your intention to warn\inform the user? If so, I would do this without a macro. I would use conditional formatting to make the cell change color whenever the duplicate information is entered.
Create a column on your worksheet with a formula that concatenates the information in column B&L the formula would be =B1&L1 (copy this formula down the table). You can hide the column so nobody sees it. For this example, let's say you used column "M".
Select the entire Code or Month column (or both) and click the CONDITIONAL FORMATTING button on the Home tab, choose NEW RULE, USE FORMULA TO DETERMINE WHICH CELLS TO FORMAT, then enter the following formula: =COUNTIF($M$4:$M$1000,M1)>1 (note I am assuming your range of data is less than 1000 records, otherwise increase that number). Set the format to something like a red fill and instantly duplicates will be flagged. The user will also be able to quickly locate the record where this combination was already entered as that will turn red too.
If you really do want a macro to do this, you could simply write a loop to compares the active cell value of B(activerow) & L(activerow) to each previous B#&L# combination. If a match is found, use the intersect method to pop-up a the message. Here is really a good article about the intersect method: http://www.ozgrid.com/VBA/vba-intersect.htm.

How to create a Dynamic Formula in a Google Spreadsheet based on a dropdown?

I have a Google Spreadsheet of containing an Employee Schedule separated daily (each date has its own page). I need to create a SINGLE summary page with a drop down that will change a formula and display the results. I currently have the formulas setup so that each employee has their OWN page depending on the employee number that shows a quick summary of when they work for the entire month. I would like to compress that into a single sheet with a way to dynamically choose from a drop down what name to see.
Here's a link to the sheet: https://docs.google.com/spreadsheet/ccc?key=0Amfumj1fHXzYdElQSGtqZkZ2aHAtdW4wM1d2WTZnMXc&usp=sharing
And here's a direct link: https://docs.google.com/spreadsheet/ccc?key=0Amfumj1fHXzYdElQSGtqZkZ2aHAtdW4wM1d2WTZnMXc&usp=drive_web#gid=34
I'm Looking to change Cell A1 into a drop down that when selected will change the 744 Formulas to look for the selected name.
Current formula: =IF((COUNTIF('1'!B3:P3,"Katie"))=0,"","XX")
What i would like to accomplish: =IF((COUNTIF('1'!B3:P3,"DROP DOWN SELECTION FROM A1"))=0,"","XX")
Dropdown will always be a text name (Bob, Sally, Dave R, Adam, Kat, etc)
Any ideas?
Have you tried?
IF((COUNTIF('1'!B3:P3,'1'!$a$1))=0,"","XX")
In this way you only need to change the value cell A1 of the sheet called 1.
As for a dropbox, DATA > VALIDATION
- Range '1'!A1
- Criteria, select LIST WITH ITEMS