I am trying to use some logic in a spreadsheet without any macros.
First I have a sinle cell that gives the date and time. I then used the custom format on that cell to just show the "h". So only hour numbers 1 through 24 appear in this cell. (e.g. at 3:20 p.m. I get 15 in the cell). (Cell # A:1)
=now()
Second, I have a separate single column with 24 rows numbered 1-24 (Cell #'s B1:B24)
I have a third column that has logic that states "Night" shift" for numbers 23 & 0-6; "Day Shift" for numbers 7-14; and "Mid Shift" for numbers 15-22) (Cell #'s C1:C24)
=if($A$1=B1,"Night Shift","")
However, the third columns all appear blank even tough one should appear. I tried changing A1 using text(A1,"#") but I get the serial number. Is there an easy way to dynamically have a value in column C show what shift based off the hour of the day in cell A1. Column D simply concatenates all 24 cells since there will only be one number ever. (Cell # D1). Thanks for any help.
You could use a LOOKUP formula to return the shift based on a time/date value in A1, e.g.
=LOOKUP(HOUR(A1),{0,7,15,23;"Night","Day","Mid","Night"})&" Shift"
Changing the format of the cell containing the date and time does nothing to the actual contents of the cell. It will still contain a value such as 43706.75 (number of days and fractions of days since 1/1/1900).
If what you want to do is determine the shift for the date/time in A1, you could use a formula like:
=IF(AND(HOUR(A1)>=7,HOUR(A1)<15),"Day Shift",IF(AND(HOUR(A1)>=15,HOUR(A1)<23),"Mid Shift","Night Shift"))
And similar logic if you need to apply different multipliers for the salary.
If you need something else, be more specific.
By doing =now() without any formatting you get the Date and the Time. Then in cell A2 do
=(A1-INT(A1))*24
Then in cell A3 do
=INT(A2)
This gives you the hour number extracted from a date format so a comparison can be made in column C against the numbers in column B. Thanks.
Related
I am a beginner at excel. I want to multiply a cell with a number as the input given in another cell.
Cell A1 has the Input that is the duration(week/s) which is 1/2/3/4...
Cell A2 has the Start Date(i.e. Monday)
Cell A3 has the End Date(which is supposed to be Friday) which I want to calculate as per the number of weeks I enter in the Cell A1
Example:
If the Start Date(A2) is 14-02-2022 and the Duration(A1) is 1 week, the End Date(A3) should be 18-02-2022.
I tried with =A1*IF(A2=1,1.0001, IF(A2=2,1.00026)), to which I got the results. But when I tried to add the formula for the further durations, it said that I have entered too many arguments for this function.
How can I write a formula to handle the multiple durations?
Your start date can be any weekday (Monday-Sunday) and the formula will return always a Friday. Notice how rows 6:9 return same results even if the start date are not Mondays.
Formula in column C:
=7*(A2-1)+(B2+(5-WEEKDAY(B2;2)))
Please, notice I'm using an european WEEKDAY setup, that means that first day of week is Monday (in other countries is Sunday). If you change this, you'll need to adjust the whole formula:
WEEKDAY
Function
I have a worksheet and I'm trying to do a simple Count function, probably a countif but I'm unsure how to go about writing the formula.
I have two columns that I'd like to use for this formula.
Column N - I would like to filter for the Criteria of "C" or anytime a cell has a value of C
Column 0 - This column has dates filled in (short date format).
I would like to get a count of every C for each month, as simple as that.
In this example I filtered the date for May of 2017 and filtered for C under the Check column. We can see that there are 12 instances of C showing in the month of May 2017.
Does anyone know how to structure a formula that I would be able to Count the Number of C's for every month into the foreseeable future?
I figured out how to count the total present in a date range but unsure of how to add the date range plus Column N (Check) every time "C" is present in the cell.
=SUMPRODUCT((O:O>=DATEVALUE("5/1/2017"))*(O:O<=DATEVALUE("5/31/2017")))
Try this
=COUNTIFS(O1:O100,">="&A1,O1:O100,"<"&B1,N1:N100,"C")
Where A1 has the start date and B1 has the end date for that month. You can use DATEVALUE() instead of A1 and B1. Change as applicable
Screenshot
If you want to use SUMPRODUCT then see this
=SUMPRODUCT((O:O>=DATEVALUE("1/5/2017"))*(O:O<=DATEVALUE("30/5/2017"))*(N:N="C"))
In another column (lets say 'P' for example) I would insert a formula to give you the month number =Month(P7) - this will return 5 for May.
I would then use COUNTIFS (Like COUNTIF but it uses multiple criteria) to count where column N contains 'C' and column 'P' contains '5'.
=COUNTIFS(N:N,"C",P:P,5)
Try this....you need to select the entire Column B and named the column as 'Date'.enter image description here
I'm building a yearly shift roster and I'm trying to figure out how to apply the conditional formatting to show where the weekends are. Figuring out how to define the weekend is easy, the problem here is getting the conditional formatting to cooperate with that rule.
Here's how I have my table set up for anyone trying to replicate this:
Row 1 - =LEFT(TEXT(row 2,"aaa"),1) this displays the single letter day of the week based on the date in row 2
Row 2 - The date, formatted to DD. A2 starts with 1/1/2016, B2 is =A2+1 and that is repeated all the way to column NB (=NA+1)
The conditional formatting formula I'm using is =WEEKDAY($A$2,2)>5, applied to $A$1:$A$15. Now this works great for column A, but when trying to copy it over to column B the rule is still referencing column A (however it will apply it to column B). What I'm struggling to figure out is how to get the conditional formatting rule to look at all 365 columns and then apply the conditional formatting to that single column and not the entire range. The end result here would be that the weekdays have no fill applied while the weekends are shaded.
The solution to this is to use =WEEKDAY(INDIRECT(ADDRESS(2,COLUMN())),2)>5.
Here's what's going on in each part, starting inside and working out:
COLUMN() returns the column number of the current cell (A=1, B=2, C=3, etc...), so for the sake of this example let's say you had cell A2 selected, COLUMN() will then return 1.
ADDRESS(2,1) returns a TEXT string of the absolute cell reference ("$A$2"), in this case locked to row 2.
INDIRECT("$A$2") converts the text string into the A2 cell reference.
WEEKDAY($A$2,2) evaluates the date in cell A2 (1/1/2016) and returns a numerical value based on what date of the week it is. The 2 argument sets the week as Monday (1) through Sunday (7). In this example WEEKDAY() will return a value of 5 (Friday).
I need a formula that can find the date in a cell next to another that has the first number in the column.
In column A I have dates and in column B onward I have stock prices. The dates goes back to 1990 daily, but not all the stock prices starts there. All of the prices end at 20-05-2015.
For all the stocks, I need to find out how many days they have been traded. I have the end date, but I need to look up the start date.
Therefore, I need a formula that says "Lookup the first cell which is numeric in column B, and take the corresponding cell in column A".
Thank you
You can use an array formula like this, assuming you have up to 1000 rows of data
=INDEX($A1:$A1000,MATCH(TRUE,ISNUMBER(B1:B1000),0))
confirm with CTRL+SHIFT+ENTER
Given a date, ex. 05/05/2006, I need to name 12 columns starting with the month of the date given. I realize that I need to make a list of months, I just don't know how to loop it (ie. if one of the months in the middle is December, the next one needs to be January).
The only way I know, from other programming experience, is to make the first column equal to the first month, then make nested conditional statements for the other columns
IF(A1="Jan","Feb",IF(A1="Feb","Mar".......))
I'm sure that there's a better way to do it than brute force (plus, excel doesn't allow me to input that many nested conditionals).
This formula should do the trick:
=TEXT(DATE(2014,MONTH($A$1)+COLUMN()-2,1),"mmmm")
The starting date should be in A1 and first header in B column. If the first header is in another column, you should replace 2 in COLUMN()-2 with the column number.
In the first month column, use =TEXT(A1,"MMMM") where the date is in A1... In the subsequent columns, use =TEXT(EDATE(DATEVALUE("1 "&B1),1),"MMMM") to make a date from the month name, add a month and convert to text.
Assuming your date is in A1, and your columns are in B1 - M1:
Set B1 = A1.
Set C1 = EDATE(B1, 1). EDATE adds the specified number of months to the specified date.
Copy C1 to D1 - M1.
Now you have twelve columns containing the original date and the same date on eleven successive months.
Select B1 - M1; Format Cells; under Number, select Custom; and under Type, enter mmm. This will format these dates to just show the abbreviated month.
Assuming A1 has the date. The following should work
B1= A1 (format as "mmm")
C1 =EOMONTH(B1,1) (format as "mmm")
Copy the above formula and format from C1 for the other columns
Assuming the date is in A1
=TEXT(EDATE(A1,0),"MMMM")
The next column would be
=TEXT(EDATE(A1,1),"MMMM")
... and so on.