Get Formatted Value of Cell in Excel - excel

How do you get the formatted value of a cell when using =CONCATENATE(E1, " - " , D1)?
E1 = 08/21/2014 8:00 PM EST (Formatted value = 08/21)
D1 = Task Item 1
Wanted output: = 08/21 - Task Item 1

Use the TEXT() function:
TEXT(value, format_text)
So if the value is 23.5 and you pass =TEXT(A1, "$0.00") it will return $23.50
Source: http://office.microsoft.com/en-us/excel-help/text-function-HP010062580.aspx

Building on #mmmmmpie answer,
I would go one further an argue that =TEXT(E1,CELL("format",E1)) is the better solution

Related

VBA - How can I get all Mondays in a month then multiply to working hours?

I'm trying to figure out how to get the total of Mondays in a month then multiply by working hours.
This is my example code it works but it counts wrong output:
If UCase(val) Like "EVERY MONDAY" Then
Dim numString As Integer
Dim strDays() As String
Dim wordCount As Long
numString = 2
strDays = VBA.Split(val, " ")
wordCount = UBound(strDays)
strWhEveryDay = ThisWorkbook.Sheets("Input").Cells(X, 4).Value
strWhEveryDay = strWhEveryDay * var_month
Debug.Print "Every = " & strWhEveryDay
Explanation:
It depends on the user if what they like to input in a TEXTBOX. However, the CALCULATION it depends on the date where the user input in TEXTBOX.
I have Textbox which is the target month where the user input the format of date like this:
**Jan-2023 or Feb-2023 **
I have a table like this:
Place this text in a table start in Column B Row 2:
**every Monday**
Place this text in a table Column D Row 4:
**1.2**
All I need is to get all the total of Mondays based on the given month and year. The calculation of the days in a table of "every Monday" once I change the text from "every Monday" to "every Tuesday" so the calculation will adjust or automatically knows where the calculation days start to end:
Example of expected calculation: every Monday (January 2023 = 5 Days) * 1.2 so, the expected result will be 5.
Note: use Debug.Print to see the result or output
So, using networkdays.intl() as suggested in my comment:
NETWORKDAYS.INTL($A$3,$A$33,"0111111",)
The result shown is 5, which is correct by inspection, for cells A3:A33 the long date format was used.
So multiplying by 1.2 is:
NETWORKDAYS.INTL($A$3,$A$33,"0111111",)*1.2
and 5 * 1.2 = 6
Also, the string "0111111" can be put in cell F5 and referred to so it is easier to edit.
The easiest way I know to recognise any day of the week is the following:
=WEEKDAY(B2,2)
The "2" means that weekdays are counted, starting with "Monday" as 1, "Tuesday" as 2, ...
So, if you want to know if your date is a Monday, you can use this formula:
=IF(WEEKDAY(B2,2)=1,...)
This can easily be translated into VBA, using a standard IF-clause.

Using Unix US Formatted Date-time-year for calculations in Excel

I have dates that are formatting using the default time formats for Bash (echo $date) for example:
Fri Dec 24 07:35:41 EST 2021
I cannot change this behavior as I don't have permissions to alter our IT solution. I need to be able to load these dates into a UK localised Excel, but any attempts to use the usual Text To Columns DMY approach doesnt work due to the Day, time zone, time etc.
Is the only way to extract the data and re-assemble it or is there a simpler solution?
Try this function . write it to module and call from any cell . Like =makeDateFromStr(A1)
Function makeDateFromStr(ByVal someDate As String) As Date
On Error Resume Next
Dim var As Variant, Mu As Long
var = Split(someDate, " ") ' array to hold all parts of the string-date
Mu = (InStr("JanFebMarAprMayJunJulAugSepOctNovDec", var(1)) + 2) / 3 ' a way to make short string month (Dec) to number
makeDateFromStr = DateSerial(var(5), Mu, var(2)) & " " & TimeValue(var(3)) ' putting all together
On Error GoTo 0
End Function
As far as I can see, if we get rid of the EST and the week day FRI, we can get a valid date value. Note: If you want the weekday, you can use the function WEEKDAY() to get the value 6, which is Friday. (1 is Sunday).
So, to get rid of the weekday, you can use the RIGHT() function.
All weekdays are 3 letters and a space, so we need to get rid of the 4 first characters, like so:
=RIGHT(A1;LEN(A1)-4)
You can put this just underneath your example time, so place this in cell A2.
To remove the EST is a bit more tricky, we need to know where in the text EST is. For this, we use FIND():
=FIND("EST ";A2)
Now we know at which position the text "EST " appears in A2.
Then we can use a simple REPLACE() function, to replace "EST " with nothing. Like so:
=REPLACE(A2;FIND("EST ";A2);4;"")
Note: The 4 refers to the length of "EST ".
This worked for this example, so you can try it out with different data. Just comment below if it isn't working correctly, and with what data and I'll look into it.
Put a date in A1
Put =RIGHT(A1;LEN(A1)-4) in A2
Put =REPLACE(A2;FIND("EST ";A2);4;"") in A3
You could also merge it into 1 cell:
=REPLACE(RIGHT(A1;LEN(A1)-4);FIND("EST ";RIGHT(A1;LEN(A1)-4));4;"")
You could then place this next to the date in A1, so in B1, and drag this formula down for ALL your imported dates. Now it should work for all of your dates.
You could also copy their values and replace the original dates, then remove the formulas, and you will have the same layout and functionality you were expecting from the beginning!

Excel sum of values if specific date is in specific period and text values are the same

I have two tables: Table11 and Table1510
In Table11 I have three columns: Date, Numeric value and Text value
In Table1510 I have 4 columns: Startdate, Enddate, Text value and empty column
Now what my formula needs to do is:
Table[1510] empty column =
If Table11[date] = between Table1510[Startdate] + Table1510[enddate]
and Table11[text value] = Table[1510]text value
Then sum all the Table11[numeric value].
I want to autofill this formula down in Table1510 so maybe I'll have to do it with an array formula but I can't make it work.
I tried the following but didn't work:
=SOMMEN.ALS('Productiegegevens nieuw.xlsm'!Tabel11[Downtime door technische fout];[#Equipment];'Productiegegevens nieuw.xlsm'!Tabel11[Equipment];[#[Datum uitvoering]];"<="&'Productiegegevens nieuw.xlsm'!Tabel12[Datum];[#[Datum eind uitvoering]];">="& 'Productiegegevens nieuw.xlsm'!Tabel12[Datum])
With the help of google translate, I've attempted to determine the problem with your formula. It looks like at least one criteria_range and criteria are out of synch and if the translations are correct then your dates have mismatched >= and <= operators.
Datum uitvoering Date of execution (startdate)
Datum eind uitvoering Date of completion (enddate)
Downtime door technische fout Downtime due to technical error (numerical value)
Equipment Equipment (text value)
You will have to add the external workbook name to Table11 but this is what I came up with.
=SUMIFS(Tabel11[Downtime door technische fout], Tabel11[Datum], ">="&[#[Datum uitvoering]], Tabel11[Datum], "<="&[#[Datum eind uitvoering]], Tabel11[Equipment], [#Equipment])

Compare two date fields using SSJS

I have two date fields in a document. I need to check if these two fields contain the same value using SSJS.
The values in those fields can either be a datetime or "not set" (empty)
how can I do that?
Thomas
The easiest way is to compare the String values of the dates:
var d1 = document1.getItemValue("date1").toString();
var d2 = document1.getItemValue("date2").toString();
return d1 == d2
When you want to compare only dates, you can do this by converting the date using SimpleDateFormat java class.
var sdf = new java.text.SimpleDateFormat("YYYY-MM-dd");
var d1 = document1.getItemValueDate("date1");
var d2 = document1.getItemValueDate("date2");
d1 = d1 == null?"":sdf.format(d1);
d2 = d2 == null?"":sdf.format(d2);
return d1.equals(d2)
You can adjust the formatting in the first line to comply to your needs.
More info on formatting can be found here

find earliest date for two different strings in the same column

I have a column of data containing work order states, and another column indicating the date the work order is scheduled to finish. I need to work out the earliest date for a work order with a state of 'WCON' or ACK'
I use this formula
=SMALL(IF(OR('Raw PM Data'!$E$2:$E$999="WCON")*('Raw PM Data'!$E$2:$E$999="ACK"),'Raw PM Data'!$L$2:$L$999),1)
Column E has the states and column L has the date.
It works fine if the data set has both a ACK and WCON entry, however if the data set has no 'ACK', the formula breaks and '!NUM' is reported.
Can someone please point me in the right direction to resolve the problem
Thanks
Garry
Try using a + instead of the OR. Array formulas do not like OR or AND qualifiers:
=SMALL(IF(('Raw PM Data'!$E$2:$E$999="WCON")+('Raw PM Data'!$E$2:$E$999="ACK"),'Raw PM Data'!$L$2:$L$999),1)
This is an Array formula and must be confirmed with Ctrl-Shift-Enter.
This works in that any row that has "WCON" or "ACK" will return true; > 0. Those rows will be then used to find the smallest. One will be zero and the other 1. So adding them together you get 1. If neither it would return 0.
Since you are finding the first smallest you could also use MIN:
=MIN(IF(('Raw PM Data'!$E$2:$E$999="WCON")+('Raw PM Data'!$E$2:$E$999="ACK"),'Raw PM Data'!$L$2:$L$999))
Use the * or ultiple IF statements when wanting the AND qualifier.
Just to show it works:
Instead of writing a complex formula in cell, I've created a public function with the use of visual basic, which can be used as a personalized worksheet function.
First bring up the VB Editor by pressing "alt-F11", that should bring up a window like this:
In this window you'll have to add a module, by clicking insert and then module, which should result in an empty code module, in there you can past the following code:
Option Explicit
Public Function SMALLIF(Criteria1 As Variant, Criteria2 As Variant, CriteriaRange As Range, DataRange As Range) As Variant
Dim i As Long
Dim arrDat() As Variant
Dim arrRes() As Variant
ReDim arrRes(0)
arrDat = Union(CriteriaRange, DataRange)
For i = LBound(arrDat, 1) To UBound(arrDat, 1)
If arrDat(i, 1) = Criteria1 Or arrDat(i, 1) = Criteria2 Then
If UBound(arrRes) = 0 Then
ReDim arrRes(1 To 1)
arrRes(1) = arrDat(i, 2)
Else
ReDim Preserve arrRes(1 To UBound(arrRes) + 1)
arrRes(UBound(arrRes)) = arrDat(i, 2)
End If
End If
Next i
SMALLIF = arrRes(1)
For i = LBound(arrRes) To UBound(arrRes)
If arrRes(i) < SMALLIF Then
SMALLIF = arrRes(i)
End If
Next i
End Function
So it should look something like this:
Now you can close the VB editor and you can write the following in a cell:
=SMALLIF("WCON"; "ACK"; 'Raw PM Data'!$E$2:$E$999; 'Raw PM Data'!$L$2:$L$999)
This should now return the earliest date for the work orders with states WCON and ACK.
(keep in mind that your Excel might use , as argument separators while mine uses ; argument separators
I would recommend to implement as per below. Added new column with maximum possible date (eg: 31/12/9999 i specified in F2).
I then used formula M2=IF(OR(E2="WCON",E2="ACK"),L2,$F$2) and then dragged this formula till M999 ie., M999=IF(OR(E999="WCON",E999="ACK"),L999,$F$2). I then used formula =SMALL(M2:M999,1) to get the minimum value.
Formula in M
Formula in O2
Scott Answer - This answer is correct. Press ctrl+shift+enter.
Edit: Removed screenshot about Scott answer. His answer is correct.

Resources