Concatenation of string in excel having today() function - excel-formula

In a cell in excel i want to concatenate a string that contain format as below ---
Brett201505LeeMay15
I am trying to do that by today function like -
= "Brett" & Today() & "Lee" & Today()
issue is how to specify date format as "yyyymm" and "mmmyy" in a single cell.
Write now when the cell format is general i am getting some number. I guess it is datevalue. Please help.

Use this expression :
="Brett"&TEXT(TODAY(),"yyyymm")&"Lee"&TEXT(TODAY(),"mmmyy")

Related

Formatting Dates (International and American in Same Column)

I am struggling with formatting dates in Excel and am looking for some help.
I have two different date formats in the same column:
MM/DD/YYYY
DD/MM/YY
I am struggling to change the DD/MM/YY to MM/DD/YYYY. I have tried so many things and can't get it to work.
Public Function dateguesser(inDate As String) As Date
dateguesser = CDate(Split(Split(inDate, " ")(0), ",")(0))
End Function
Things I have tried:
This solution ends up thinking that the DD in the DD/MM/YY format is the year because the year is not stored as four digits.
Tried to change MM/DD/YYYY to DD/MM/YY and then convert all of them to MM/DD/YYYY.
Text to columns
If you put this formula starting in B3, I think it should work for all values?
=IF(ISNUMBER(A3),A3,DATE(2000+RIGHT(A3,2),MID(A3,4,2)+0,LEFT(A3,2)+0))
You could also probably modify your custom function to something like this:
Public Function dateguesser(inDate As Variant) As Date
If IsNumeric(inDate) Then
dateguesser = inDate
Else
dateguesser = CDate(Split(Split(inDate, " ")(0), ",")(0))
End If
End Function
I'd add another column to convert to epoch and back to new date format. https://exceljet.net/formula/convert-unix-time-stamp-to-excel-date could help
Assuming the input is in A10:A11, I made for B10:
=((A10-DATE(1970,1,1))*86400/86400)+DATE(1970,1,1)
and applied new date format to B:B.

change date format excel

I have the following date in excel "5/2/2020", I would like to obtain "5/Feb/2020", but unfortunately I am getting "May/2/2020".
Also tried to change the format of the cells , but excel still interprets that the first number is the month.
How do I tell Excel that the month is in the second position ?
Try:
If 5/2/2020 is in cell E5 then:
=VALUE(TEXT(E5,"d/mm/yyyy"))
and then custom number format this cell to d/mmm/yyyy
will yield 5/Feb/2020
OK, here is a new method tested with the following dates 5/2/2020, 22/2/2020, 22/12/2020, 12/2/2020.
This function splits the date numbers into 3 parts and places them into an array using the "/" as the split delimiter. It then reassembles the 3 parts in the order you wanted.
Step 1: Add the following Custom Function to a VBA Module:
Function Dates(Cell As Variant)
'Forces recalculation when call values are changed
Application.Volatile
Dim DateString As String
Dim DateArray() As String
DateString = Cell
DateArray = Split(DateString, "/")
Dates = DateArray(1) & "/" & DateArray(0) & "/" & DateArray(2)
End Function
Step 2: For example, enter the date you want to convert in Cell A1 (i.e. 5/2/2020).
Step 3: Put the function formula =VALUE(Dates(A1)) in Cell B1.
Step 4: Apply the custom number format to Cell B1: d/mmm/yyyy and the result will be 5/Feb/2020.
If you want to change the number format to mmm/dd/yyyy, then the result will be Feb/05/2020.
Note: the =VALUE(Dates(A1)) formula will work anywhere on the spreadsheet. All you have to do is change the cell reference A1 to another cell reference. You can also use the formula many times on the same spreadsheet.
Sammy

VBA macros use variable and cell reference in yearfrac function

I am trying to calculate the years between dates using a variable and a cell reference but so far everything I have tried returns an invalid argument (or equivalent) error. Basic premise is cells("G2").Formula = "=YEARFRAC(F2, dt)". The variable dt is equal to the last day of the previous month (I know this works because I have tested using MsgBox, so assume the issue is the syntax). The cell F2 contains a date in the form 13-Jan-2018. Can someone please advise of the correct syntax? Thanks.
You're inserting this formula into the cell as a string using VBA. The string "dt" will therefore be inserted verbatim (not the variable).
If you want to insert the date value of dt as stored in VBA at the time, you'll have to use:
Dim dtstr as string
dtstr = Format(dt, "yyyy-mm-dd")
Range("G2").Formula = "=YEARFRAC(F2, DATEVALUE(""" & dtstr & """))"
Note that I have converted dt to a string value for insertion into the cell formula in a standard format.

Copying date Word to Excel - wrong format

I have been trying to solve an issue I have with copying dates from Word document to Excel using VBA.
My issue is the format. If I put dd/MM/yyyy it will change during the process to MM/dd/yyyy and I cannot solve the issue.
Basically for copying I am using this line:
Sheets("wImp").Range("AA" & i) = wdDoc.ContentControls(1).Range.Text
However during the process the data is modified.
I originally used LegacyForms but it did work and I hoped Date Picker would help but it does not. And in a case the date is impossible to switch like 21/12/2017 it will stay as it should. But when it can be switched like 1/5/2017 it will be switched to 5/1/2017.
!!! Nevertheless the cell format stays dd/MM/yyyy for all the dates, but the months and days position is switched.
See below for what I have as input in Word and the output in Excel.
Word:
Excel:
If you want to use the continental date format "dd/mm/yyyy" in your sheet you must use Format() function. So, try this:
Sheets("wImp").Range("AA" & i) = Format(wdDoc.ContentControls(1).Range.Text, "dd/mm/yyyy")
Sheets("wImp").Range("AA" & i).NumberFormat = "dd/mm/yyyy"
Oficial documentation of Format() function
Sub test()
ActiveSheet.Range("A1").NumberFormat = "#"
ActiveSheet.Range("A1").Value = "01/05/2017"
ActiveSheet.Range("A2").NumberFormat = "m/d/yyyy"
ActiveSheet.Range("A2").Value = "01/05/2017"
ActiveSheet.Range("A3").NumberFormat = "yyyy/m/d;#"
ActiveSheet.Range("A3").Value = "01/05/2017"
End Sub
Try something like this.
Excel will convert the data during copy.
So, change "NumberFormat" before copy.
Assigning a string to the cell makes Excel think that the string should be interpreted in a "mm/dd/yyyy" format irrespective of your locale (and irrespective of the cell's date format).
So convert the string to a Date using the CDate function (which will be done using your system date/time settings) before assigning the value to the cell.
Sheets("wImp").Range("AA" & i) = CDate(wdDoc.ContentControls(1).Range.Text)
That date can then be displayed in whatever date format you want to use for the cell.

Using Today() and Mid in excel

Excel cell should have the below value
ABC,04-04-2014
the date entered shouldn't be hard coded.
I need it by using
Today() or some other function.
Either:
="ABC," & TEXT(TODAY(),"dd/mm/yyyy")
or
="ABC," & TEXT(TODAY(),"mm/dd/yyyy")
depending on your desired date format.

Resources