How to set the value of a cell depending of 2 other criteria - vba

I have an Excel tab like this.
It give me information on when a worker is plan to start on a product.
The Columns of my input Table are:
Product Number, Dummy column, Dummy column, Worker ID, Starting Date, Ending Date
The lines in my input Table are:
Product 1,xyz,xyz,Worker 1,13/08/2018 13:50,20/08/2018 15:30
Product 1,xyz,xyz,Worker 2,08/08/2018 03:50,16/08/2018 08:30
Product 1,xyz,xyz,Worker 9,23/08/2018 08:08,03/09/2018 10:00
Product 2,xyz,xyz,Worker 4,10/08/2018 13:50,27/08/2018 15:30
Product 2,xyz,xyz,Worker 9,18/08/2018 03:50,20/08/2018 08:30
Product 3,xyz,xyz,Worker 2,13/08/2018 08:08,13/09/2018 10:00
My Result table should have:
one line per Worker
one Column for each day of the year
The values in the Result Tab should show for a given Worker and a Given Date on which Product the Worker started to work.
So the cell could be empty if at this date the workerX didn't start to work on a product.
Do you have an idea how I can solve this in Excel (or Access if not possible in Excel)?

Access is probably going to be your best bet. You will want to create a column that strips the time value from the Starting Date column, leaving you with only the day value. Let's call that the Starting Day for now. Now create a crosstab query based on your table. The rows will be based on the Worker ID column. The columns will be based on the Starting Day column. The value will use the aggregate function called "First()" on the Product Number field.
I think it should look something like this in SQL (replace <YOURTABLE> with your table name):
TRANSFORM First([Product Number])
SELECT [Worker ID] FROM <YOURTABLE> GROUP BY [Worker ID]
PIVOT [Starting Day]
Good luck!

Transfer your data in column A.
In cells C2 to C20, type the names of the workers Worker 1, Worker 2, etc, in the same way as it is present in the data.
In row 1, enter the dates, starting from cell D1.
In my example, cell D1 is 7 Aug 2018, E1 is 8 Aug 2018., …
In cell D2, enter the following Array Formula
=IF(MAX(IFERROR(FIND($C2&","&TEXT(D$1,"dd/mm/yyyy"),$A$1:$A$1000,1),0))=0,"-","Yes")
Array Formulas are entered using Control + Shift + Enter, instead of Enter.
Drag the formula to the required cells.
The result will be "Yes" if a worker has started a project on a particular date, and "-" if no project has been started by a worker on a particular date.
Change the cell references as required.
In place of "Yes", if you want to get the Product details as the result, then use the below Array Formula in cell D2.
=IFERROR(LEFT(IF((MAX(IF(IFERROR(FIND($C2&","&TEXT(D$1,"dd/mm/yyyy"),$A$1:$A$1000,1),0)>0,ROW($1:$1000),"-")))=0,"-",INDEX($A$1:$A$1000,(MAX(IF(IFERROR(FIND($C2&","&TEXT(D$1,"dd/mm/yyyy"),$A$1:$A$1000,1),0)>0,ROW($1:$1000),"-"))),1)), FIND($C2,IF((MAX(IF(IFERROR(FIND($C2&","&TEXT(D$1,"dd/mm/yyyy"),$A$1:$A$1000,1),0)>0,ROW($1:$1000),"-")))=0,"-",INDEX($A$1:$A$1000,(MAX(IF(IFERROR(FIND($C2&","&TEXT(D$1,"dd/mm/yyyy"),$A$1:$A$1000,1),0)>0,ROW($1:$1000),"-"))),1)),1)-2),"-")
Do let me know if this is what you wanted to do.
Regards,
Vijaykumar Shetye,
Spreadsheet Excellence,
Panaji, Goa, India

Related

Microsoft Access- How to create dynamic variables that queries a selection of Columns

Example Data Picture
My main data table is constructed in the following way:
1.State
2.Product
3.Account Name
4.Jan-20
5.Feb-20
.
.
.
N.)Recent Month- Recent Year
My goal is to get 6 total sums based on 6 different contiguous that are user selected. For example, if someone wanted the value of an Account Given a State and Product for FY-2020, they would sum columns 4 to column 15 (Twelve Months).
I am going to be running joins and queries off of the State, Product, Account combinations (first three columns), but I need to create a method to sum the Data table given a list of Column Numbers.
At this point, I am not looking to put non-contiguous columns in a selected Time Period (i.e. all time period selections will be from Col.Beg_TPn to and including Col.End_TPn). The Data Table houses monthly data that will have one new column every month. The Column Number should stay consistent as we are not looking back further than FY-2020.
This a much easier problem in Excel as you can do a simple SumIfs with an Index of the Column Range as the SumRange and then you filter on Columns 1,2,3. My data table is about 30,000 rows, so Excel freezes on me when could calculations and functions on the entire data set.
What is the best way to go about this in Microsoft Access? Ideally, I would like to create a CTE_TimePeriodTotals that houses the First 3 Columns (State,Product,Account) and then 6 TP Columns (tp-1,tp-2...) that holds the sum of each time period for each row based on the Time Period Column Starts and Time Period Column End.

I need to convert total date to month only

I set up a google forms form for my work where my employees pass information and this information is recorded in a spreadsheet. The information, when recorded, automatically inserts a date and time in the first column of form responses. However, when I enter the code = month (a1), it always returns the answer "1" or "January" and this information does not match the date entered in the column. How do I fix this?
If you are entering '=month(a1)' for every row, then you are always taking the month of the top left cell in the sheet. You would need to adjust the row number for the row you are in.
You could use something like '=month(now())' to ensure you are always getting the month of the current date.

Display all dates even if there is no data

I am attempting to display all the dates within a range even if they do not have data for the particular date.
Our employees do work 24/7 365 ( like everyone else) so there are dates within my time range that wont pop up. What i have tried is to add and exception that states even if the date has a null to display that particular date.
Currently i have a crosstab with the row being the numbers of items completed and the columns being the date that the item was completed.
For a visual:
04/01/19 04/02/19 04/03/19
1 2 3
I would like to continue that till the end of my range (the month) but my data skips if nothing was completed for that date.
What i currently have:
04/01/19 04/04/19 04/05/19
1 6 8
For the rows I have this in the formula bar for my row.
If [Items Completed]> 0 Then [Items Completed)] Else 0
For the columns I have this in my formula bar
If IsNull([Completed Date]) then 0 Else [Completed Date]
Thinking this would give me a 0 in those columns where nothing was done.
You need to create a variable and use the TimeDim function like this...
All Dates = TimeDim([Completed Date])
Then replace [Completed Date] in your table with the [All Dates] variable. You can name it whatever you want. This will result in blank values for the dates for which you do not have data. If you want to have zeroes display for the dates with no data you can apply a custom format setting "Undefined" to "0".
You can find a more thorough explanation with possible variations here.
Enjoy!
The TimeDim method was the basis for me achieving what I needed - namely a line chart that displayed zero values if no one had completed a training course on a particular date in my range. I work in Learning Management System software so this is often required.
The object in my case is called [Course Completed Date (Success)], so here's my variable (which is a dimension, not a measure):
=TimeDim([Course Completed Date (Success)])
Note in my screenshot how the zeros and now displayed. Previously they were missing.

how to group rows based on a dates in a single column

I have a range of date (A1:CY7026) with a column for start dates. this column has a large amount of repeated dates within it. i need these dates group together based on the working week they are located in (eg. all values reading 16/7/18 - 22/07/18 would be one group and the following week would make up another).
Use below in B2 cell (Suppose you had a header column) and drag to the rest. Sort to obtain the desired result.
=CONCATENATE(YEAR(A2),"-",WEEKNUM(A2))

Look back through a row and find the last time I wrote a particular word

I have a table that I am creating in relation to toolhire and I have many columns for on hire / off hire / days utilised. in the columns next to the on hire and off hire dates, I have it set to write the words ON and OFF when a date is entered into that cell. I want to set up a column at the end of the table which will look back through the row and tell me whether the item is currently ON or OFF by finding whether the last word it finds is ON or OFF.
If a row spans ColumnsA:M say, and contains only blanks, numeric values or ON or OFF then please try, say in ColumnN and for Row2:
=INDEX(A2:M2,MATCH("zzz",A2:M2))