Adding values of column based on employee attendance - excel

I have an excel sheet with the following data
I need result something like below
The VBA code must consider code say 12 and add corresponding dates say 02-jan login hours, next it should add 03-jan hours. For example,
code 12->02-Jan = 08 and 03-Jan = 9. Then for code 15->02-Jan =6 and 03-Jan=8 Likewise it should repeat every code in a loop and put each result in another column. Is there a way to solve using excel VBA. All I have done is do for specific cells but unable to generalize.

Related

How to extract the value of an Excel cell at a specific time?

I have an Excel cell that contains a value that is dynamic and being automatically updated throughout the day (This is done using the RTD() function that gets the data from the ThinkorSwim Trading Application) . I am trying to capture the value every minute, put it in a dynamic range and have a plot of these values being dynamically updated throughout the day; like charting a stock price dynamically minute by minute)
My proposed solution is to create a column that contains all the times in the day, minute by minute as static values and another column that captures the value from the dynamic cell at each point in time. The problem I'm facing is how to evaluate a formula at specific times.
Something like:
time value
10:31:00 Grab value from dynamic cell at 10:31:00
10:32:00 Grab value from dynamic cell at 10:32:00
..
Right now, I'm trying to learn how I can do this with Macros.
Any hint/help is appreciated.
Update: I was able to solve the problem following Mathieu's suggestion. Please see below.
I was able to solve the problem, following Mathieu's suggestion and finding the video below.
https://www.youtube.com/watch?v=svlbqdGE4ws
Here's the gist of it:
Use the following Macro code and replace the two placeholders with your Excel cell names. The destination cell will be updated based on the value of the dynamic cell every second. Right now the code gets into a loop, but that should be easy to solve. This code doesn't exactly do what I wanted to do, but shows how the content of one cell can be updated based on another cell's value at different points in time.
VBA code:
Sub timer()
Application.OnTime Now() + TimeValue("00:01:00"), "main"
End Sub
Sub main()
Range("Reference_the_Destination_Cell_Here").Value = Range("Refernce_the_Dynamic_Cell_Here").Value
timer
End Sub

For Loop for Formula that Changes Cell References

I am trying to perform ratio analysis for a collection of financial statements, each of which are contained in a separate excel worksheet. The layout and format of each sheet is exactly the same. See below.
Financial Statement Sheet
For the ratio analysis section I have a separate worksheet where I want to make an array of the computed ratios. See below.
Ratio Analysis Sheet
Unfortunately, I really don’t want to click through each worksheet to create these formulas and would rather write a script with a FOR loop. Since I need to find a ratio for every year of the financial statement the formula itself will need to continuously shift columns to derive a ratio for every year.
This is where I’m stuck. I’m not sure how to loop through every cell of my ratio summary array and use a formula that also changes for each year of the financial statement. I’m thinking I need to make a nested for loop, but I’m really not sure how to attempt the script.
Can anyone do me a huge favor and suggest how I might even start planning this out?
My VBA Developer Console
Here's what I have started, but I need more to figure this out. I don't think my formula will shift columns with this script, and I need help putting the computed values into the array on the ratio analysis sheet.
Sub Current_Ratio()
Dim Current_Ratio As Integer
Dim FirstYear As Long, LastYear As Long
FirstYear = 2015
LastYear = 2019
For i = 1 To Worksheets.Count
If Worksheets(i).Name Like "*Balance Sheet*" Then
For y = FirstYear To LastYear
Current_Ratio = Worksheets(i).Range("F21").Value / Worksheets(i).Range("F51").Value
'need line to place the computed current ratios into range B3:B37 on sheet17(Ratio Analysis)
Next y
End If
Next i
End Sub
Are you open to a formula solution rather than VBA? Here's how I would try it first. I say "try it" because the INDIRECT() function is slow and if you have too many formulas you might not like the performance. But I wouldn't make that judgement until I tried it.
I have a sheet named Company 1 Balance Sheet and in B21:D21 I have 10, 15, and 20 respectively. In B51:D51 I have 20. I also have a sheet named Company 2 Balance Sheet that has the same numerators but 30 as the denominator.
Here is the formula in C2
=INDIRECT("'"&A2&" Balance Sheet'!"&CHAR(66+VALUE(SUBSTITUTE(SUBSTITUTE(B2,"T-",""),"yr","")))&"21")/INDIRECT("'"&A2&" Balance Sheet'!"&CHAR(66+VALUE(SUBSTITUTE(SUBSTITUTE(B2,"T-",""),"yr","")))&"51")
I started by pointing and clicking to build this formula
='Company 1 Balance Sheet'!B21/'Company 1 Balance Sheet'!B51
Then I used INDIRECT to build that formula as a string so I could change the inputs. Let's take just the numerator portion because it works the same for both. My company is in column A, so I can start by replacing that part of the formula
=INDIRECT("'"&A2&" Balance Sheet'!B21")
The Balance Sheet portion of the name will be consistent, so I'll leave that. I'll need to change the B to refer to the proper year. I'll start by making that variable. The letter B is 66 in the ASCII character set.
=INDIRECT("'"&A2&" Balance Sheet'!"&CHAR(66)&"21")
Now I can add whatever year I want to 66 to increment that. My year is in column B, but it has a lot of crud around it. First I need to isolate the numeric portion
=SUBSTITUTE(SUBSTITUTE(B2,"T-",""),"yr","")
That gets rid of the stuff around the number. Then I use VALUE to turn it into a number. I can add that number to 66 so that T-1yr refers to 67 which is C.
And that's it. It's a little painful to set up, but once it's done, you just copy it down. Note the Div/0 errors means you don't have data for that year. Once you're formulas are working the way you want, wrap it in an IFERROR() function to hide those.
In your example, the company name is not repeated on every row. That doesn't work well for this method, but you can have a column where the company is repeated a simply hide that column if your particular presentation is important.
Other things you can with hidden columns: Put in the sheet's name if you don't consistent sheet names or if you just want the formula to be a little easier to read. You could also put the 21 and 51 in hidden columns and refer to those in your indirect function.

Excel Formula to Count Values between Dates

I am looking for a way to count how many companies are in Column C on the specific dates of column A. Can one formula be applied to the count between all of dates?
I have tried looking up and using =CountBlanks and I do not want to have to manually select the cell ranges between the dates.
Ultimately I am also trying to put this data into a table so I can see on Feb 16 = 3 Companies, Feb 19 = 5. I can not use a VBA script as some users have macros blocked.
Please look at image for example
Example Image
Try this formula:
=COUNTA(INDEX($C$2:$C$21,MATCH($E2,$A$2:$A$21,0)):INDEX($C$2:$C$21,MIN(IFERROR(MATCH(TRUE,INDEX($A$2:$A$21>$E2,0),0),9999999),MATCH(TRUE,INDEX($C$2:$C$21="",0),0))-1))
Change the 21s in the formula to at least the extent of your data +1, It can be more, Full column references will not work due to the Word "Date" in the first row.
DATEDIF( start_date, end_date, interval )
you didnt even bother to google this, right?
edit: there should be enough common place stuff like isblank to accommodate the lack of values. If youre trying to find the values between A & C then you can easily adjust your formula accordingly.

Excel count based on values of 2 columns

I have an Excel 2007 (xlsx) spreadsheet which has a table within it. The table has a column for date and a column for completed. I would like to do a count where the Date is today or earlier and where completed is not "Y"
The syntax I have put together is:
=COUNTIFS(UnitClosures[Completed Y/N], "<>Y", UnitClosures[Dismantling Date],"=< F7")
Cell F7 contains today's date.
When I use this I get 0 back despite having multiple columns not set to completed with a date earlier than today.
How can I change the syntax of my formula to get it to work?
Thanks!
The final criterion syntax is wrong, F7 has to be outside the quotes and concatenated - try like this:
"=<"&F7
so formula becomes this:
=COUNTIFS(UnitClosures[Completed Y/N], "<>Y", UnitClosures[Dismantling Date],"=<"&F7)

sumif some columns value based on other column

I created the time log for what I do:
To better illustrate, I attached the image as follows:
where start and end are the time when I started the particular task in the column A, and delta is the difference between the values in End and Start.
In the next sheet, I created the the summary of how much time I spent on each criteria like this:
Now the problem I had is:
1) The formula I have in the hour field in the summary sheet is this:
=sumif('Time spent'!$A$2:$A$100,A3,'Time spent'!$D$2:$D$100)
How do I make it so that values are up for the entry put in today? The reason why I want this feature is so that I can see my performance for today.
I have this on Google Doc, but I also would like to know how to get this done in Excel as well
In Excel, starting in version 2007 you can use the SUMIFS function - which allows multiple conditions. In your case, the syntax would be:
=SUMIFS('Time spent'!$D$2:$D$100,'Time spent'!$A$2:$A$100,A3,'Time spent'!$E$2:$E$100,TODAY())
In Excel 2003, you can do this with a SUMPRODUCT:
=SUMPRODUCT('Time spent'!$D$2:$D$100*('Time spent'!$A$2:$A$100=A3)*('Time spent'!$E$2:$E$100=TODAY()))

Resources