Transfer data from one worksheet to the next based on cell values - excel

I had trouble titling this, and I think it is better explained with examples. I am not an extremely experienced excel user, but was asked to figure this out.
Worksheet 1 (delivered by software) is formatted like this:
12/17/2013
Hour Delivered
00.00-00.59
Employee 1 18
Employee 2 17
Total For Hour 35
01.00-01.59
Employee 1 18
Employee 2 17
Employee 3 12
Total For Hour 47
... etc until hours 24.00-24.59
The number of employees in the group per hour is different each day, so i don't think that I can just simply reference the cells.
The worksheets that I want to transfer the data from worksheet 1 to are based on date, so there is one for each day. (12/17 worksheet, 12/18 worksheet, etc...)
And this is the format of the date worksheets:
Employee 00.00-00.59 | 01.00-01.59 | etc. until hours 24.00-24.59
Employee 1 18 18
Employee 2 17 17
Employee 3 12
Employee 4
Employee 5
So basically I need the data from worksheet 1 transferred over to the individual date worksheets. I believe, the amount of employees being different for each hour/day makes this difficult. Does anyone here have any ideas of how this can be accomplished?
Also, if there are any questions, please let me know.

This should be possible without any VB in two steps. First step is to add further columns to Worksheet 1 that normalise the data. Second step is to create a pivot table using that normalised data.
By "normalise" I mean add columns in Worksheet 1 for Date, Hour, Employee and Delivered using formulae that copy values from your existing columns A and B. Let me know if you need more help with that.
Edit: adding details ...
Suppose Worksheet 1 has the values you indicated in column A and B, and that you want Hour in column D. Suppose row 1 just contains column headings. Leave row 2 totally empty. The formula in col D needs to say "If the value in col A looks like an hour, then copy it, otherwise repeat the hour from the line above." A simple way to determine if a row in Worksheet 1 is an Hour is to look for a decimal point in position 3. So put =IF(MID(A3,3,1)=".",A3,D2) in cell D3 and copy that formula down.
I'm sure you can construct a similar formula for the Date, Employee and Delivered columns.
Maybe add a condition to the formulae to say "If the value in col A starts with 'Total' then leave the cell empty".

If there aren't a lot of data and the setup is exactly how you've displayed them above, a simple formula can solve this.
Assuming that my raw export is in sheet Base, cell A1 and my intended output starts in sheet Output, cell A1, you can use this formula on cell B2:
=IF(INDEX(Base!$A:$A,MATCH(B$1,Base!$A:$A,0)+ROW(1:1),0)=$A2,OFFSET(INDEX(Base!$A:$A,MATCH(B$1,Base!$A:$A,0)+ROW(1:1),0),0,1),0)
The premise is simple. It locates the correct hour using INDEX + MATCH, then OFFSETs it by the correct number of ROWs. This is assuming, of course, that your employees are in the same location under every hour (ie Employee 1 is always one (1) row below the hour, Employee 2 is always two (2) rows below, etc). We also add a check if the employee name matches so that it will return 0 if the employee is not there.
Here are some screencaps:
Sample data:
Output:
Of course, this is just the basic premise. If you have multiple dates in a sheet, it's just a matter of manipulating this formula further. Off the top of my head, locating the correct date and adding the correct offset can also work.
Let us know if this helps or if a VBA or the Pivot option seems best.

Related

Need help referencing another excel sheet cell based on date

I am trying to build a workbook with 4 tabs for a small business.
There are 3 locations, and the first tab will be a scorecard of sorts.
So, on the first tab (named scorecard) I have something like
Date: August 30, 2017
loc sales
location 1 500
location 2 500
location 3 500
the other 3 tabs are names loc1,loc2,loc3 and each one is set up for 31 days going vertically like:
1 500
2 500
3 500
what I want is for on the scorecard sheet, to be able to select a cell on say loc1 sheet based on the date. I know how to reference other sheets, I just don't know how to reference a specific cell on the second sheet bases on the date entered in the first sheet.
So say today, August 30, it would pull =loc!1B30 for sales, =loc!C30 for customer count etc
I hope that makes sense, if not I can try and explain better
Is each cell for sales amount associated with a date? If so, you can use a "VLOOKUP" formula. Check out this page for a further explanation.
https://www.techonthenet.com/excel/formulas/vlookup.php
Using VLOOKUP, the "value" would be the cell of the date on the scorecard tab, the "table" would be the dates and sales values on the locX tab, the "index number" would be the column number in the table you select (probably 2 for you I assume if there is a date, then value), and the last portion of VLOOKUP would probably be set to false. That would be true if there were several of the same date for sales, but I doubt that from what I understand.
It would look like this:
=vlookup([date cell reference],[table to look up value in],[column number in table],false)

i want to have a single column containing different values for each month

I have created a table in excel for keeping the leave records of staff. I created a scroll bar to scroll to a different month. I have added an extra column named "leave this month" which shows how many days a person has taken leave. but when I scroll to a different month (for example from January to February) the column's data stays the same. I want it to have different data for different months. for example for January it is 3 days, for February it is 4 days and... I want different values in the same cell for different months.(when I scroll to a different month the value should change) do you guys know how to do that?
screenshot
Sub showcalendar()
LeaveTracker.Columns("C:NJ").Hidden = True
LeaveTracker.Range(Columns(Range("B3").Value * 31 - 28),Columns(Range("B3").Value * 31 + 2)).Hidden = False
End Sub
Here is the approach I would use:
Define a spreadsheet with 31 X 12 columns (each group of 31 columns would represent a month, even for those cases when the month has 28/29/30 days); this spreadsheet will be use as the storage of the raw data (i.e. presence/absence of a person each day of the year),
A second spreadsheet to be use for display will have the cells linked to the first one with an horizontal offset (to the right) to be calculated as 31 * (month_number - 1); as such, when looking at the information of March, the offset would be 62 columns to the right.
Your scrollbar would run from 1 to 12 and set the value of the month (which would then be used to calculate the offset.
In this way, you don't need to copy-paste anything and, instead, you have a sliding "window" that runs right and left over your raw data sheet.
Hoe this description is clear.
So you basically have 365 columns for each day of the year. On row 4(or wherever suitable) add the month number i.e. for the first 31 columns, cells will have 01 in row4. For the next 28 columns cells in row 4 will have 02 and so on.
then in NK8, the formula to be entered should be
SUMIF($C$4:$NJ$4,$B$3,C8:NJ8)
which you can drag down for each person. B3 ahs the current month number you are viewing. The formula basically sums only those cells whose corresponding cell in row4 matches the month number in B3.
Here is a Google Sheet example.

Excel Complex Conditional

Ok so I did this in LibreOffice but now I have to duplicate it to excel for my Pay Roll department since they use excel. So I am having to figure out how to convert the formulas to Excel. This is only 1 of two totaling formulas that did not convert when I saved it as Excel format.
I have the following sheet called DailyReport
I am currently calculating Column M with =SUMPRODUCT(A2:A200=A2, G2:G200)
Then on a secondary sheet I have the following second sheet WeeklyReport
Now what I want to do is if WeeklyReport Column A2 == DailyReport Column A then take the date in DailyReport Column B and test it to fall in the date range in WeeklyReport Column B and Column C with =IF(AND(DailyReport.B2>=B2,DailyReport.B2<=C2),1, 0) and if that is true add the Total Daily Hours to the total in WeeklyReports Column D from DailyReports Column M
I hope this is clear enough if not please let me know what else I can do to make my question more clear.
Thanks in advance!
So, to me it sounds like:
You want a sum of all hours, for a specific employee (defined by the A column value weekly report), in between the dates specified (also defined by weekly report, b & c column) - and you want the end result to be in WeeklyReport column D and all of it to relate to the same row as the result?
sumproduct will do the trick. I am renaming your sheets to DR and WR for my sanity's sake.
=sumproduct((DR!G$2:G$200)*(DR!A$2:A$200=A2)*(DR!B$2:B$200>=B2)*(DR!B$2:B$200<C2))
Now, if you want a new daily report sheet every day it gets a bit trickier to do with formulas alone, you should then have a macro to store the "current" value and add the "new" value, or for simplicity's sake create more columns (one for each working day) and duplicate the formula to all daily columns, or have as many named dailyreports as there are working days in a week and increase the formula to check multiple sheets. I would add columns - least amount of work and the dumbest solution often proves the most resilient.
Did that help in any way?

Excel VBA Lookup Methods

I have an issue that I've been scratching my head at; I've looked into the Index:Match lookup method, and V/HLookup, but I'm not sure these will help just yet. Here's what's happening:
I have two worksheets in excel-2007. One has a Customer ID column (which does and will have duplicate ID's in the instance that the customer did "x activity" more than one time in a month) and then the date that this happened in another column. The second sheet is for giving an overview of a specific day, IE what happened on 7-1-13.
The issue is that my raw data sheet is sorted via the first of the month descending, so 7-1,7-2,etc, and when I run the Vlookup, if a Customer ID has a record on 7-2 and on 7-15, the VLookup will pull data only from the 7-2 (first) row. Has anyone experienced this and found a workaround?
My current workaround would be to make either a new table for each day's data, or instead of using my VLookup of =Vlookup(A2, 'Data Sheet' A:D, 4, 0) to give the columns row numbers, like =Vlookup(A2, 'Data Sheet' A$1:D$30, 4, 0). This is a daily report, and that would be intense. Please help if you can!
(Another side note, I have one main sheet for the view, one data sheet where it's all collected, and then 30 sheets, one for each day of the month, this case being July). For each sheet, I've named them the day of the month, so I'm reflecting the data as such:
Sheets("7-1-13") has data from the 1st on it. The Data Sheet in it's entireity has data from 7-1-13 to 7-31-13. I need to reference ID's on the 1st to the data for the 1st and the 1st only.
I want to use something like this, but I'm having a hard time with it
=Vlookup(A2, 'Data Sheet', A:D (ONLY IF THE CREATE DATE OF THIS ITEM IS 7-1), 4,0)`
but of course it's not that easy :p
This may not give you your results in a format you like and still requires a bit of manual work, but without going the route of macros, I think this will get you one step closer. I thought of using an array formula to get all the IDs by a specific date.
Example:
A B
ID Date
1 5 7/1/2013
2 2 7/2/2013
3 5 7/3/2013
In this situation, I assume you want 5 from the first row to appear on your 7/1 sheet, 2 to appear on your 7/2 sheet, and 5 from the third row to appear on your 7/3 sheet
on your 7/1 sheet. you'll need to select the number of blank rows that matches your raw data (using the example above, you would be selecting A1:A3 on your 7/1 sheet). Once you have your cells selected, then enter the following formula in the formula bar and press Ctrl+Shift+Enter. This is what makes the formula an array formula.
=((Raw_DataSheet!B1:B3=DATE(2013,7,1))*1)*Raw_DataSheet!A1:A3
What this formula does is looks at all the dates in B1:B3 and finds the ones that equal 7/1/2013. Since you're using an array formula, this gives you the array {TRUE,FALSE,FALSE}. Multiply this by 1, and you get the array {1,0,0}. You now have an array that has a 1 for each row of B1:B3 that was equal to 7/1/2013. This array {1,0,0} is then multiplied by your Customer IDs {5,2,5}
5 * 1 = 5
2 * 0 = 0
5 * 0 = 0
So now your entire formula is equal to the array {5,0,0}. Since you selected A1:A3 on your 7/1 sheet, the values that should appear should be
A
ID
1 5
2 0
3 0
From here, you can always filter out the 0's and you'd just have a list of all the IDs that had the date of 7/1 from your Raw Data Sheet. You would also then replicate this for each of your sheets and just change the date in the formula...Yes, I know, way more complicated than you probably wanted but it's what I came up with!

Excel lookup vector based on another formula

My spreadsheet has 2 sheets.
Sheet 1 contains 30 days worth of values.
Each day's values are a maximum of 19 rows, consisting of names and correspoding values. The names that will appear for each day are not the same every day. In other words my name might appear on the 1st, 2nd and 14th of the month and not on any other days. (And these values may not be sorted.)
My second sheet will display only one persons values for the month, and I therefore use a lookup.
The formula for the 1st day is:
=LOOKUP("name";'Input Sheet'!$A$2:$A$20; 'Input Sheet'!B2:B20)
For the second day it would be:
=LOOKUP("name";'Input Sheet'!$A$22:$A$40; 'Input Sheet'!B22:B40)
The only thing that changes for each day is the lookup range/vector. I have a separate (hidden) column already that has calculated the correct starting row number, i.e. 22, 42, 62, but how would I use that number to change the lookup range on my formula?
Thanks a lot
Michael
The indirect() function will allow you to specify the range for your lookup in terms of another cell.
For example, if Sheet1 of the workbook has the numbers 1-10 going from A3:A12, where the starting row (3) is specified in cell B1 of the same worksheet.
3
1
2
3
4
5
6
7
8
9
10
Then to lookup the value 5 and place the answer on any other sheet of the workbook:
=LOOKUP(5,INDIRECT("Sheet1!$A"&Sheet1!$B$1&":$A$12"))

Resources