Convert text (12.05.79) to date in excel - excel

I have imported some dates into an excel document and I need to format them as dates not text strings.
The format is like this: 12.05.79 but when I set the format to date excel doesn't do anything.
Any way to do this?
C

Two possible ways to convert "in situ" without an extra column
1 - use "Text to columns"
Select column of dates then Data > text to columns > Next > Next > "under column data format" select "Date" and the format from dropdown (MDY or DMY) > OK
2 - use Edit/Replace. Replace "." with "/" (in both cases without quotes)

Changing the format doesn't change the value (or in this case text). You'll have to use a macro, or just use a helper column with the following formula. You can then copy / paste values and remove the first column
=DATEVALUE(SUBSTITUTE(A1,".","/"))

Related

Prevent Excel "Convert text to columns wizard" from converting text to date

I have an excel file with 3000 rows. The value in A1 is 7/2-79 and in A2 7/2-80 and so on. When I tried to split these values using convert text to columns wizard, I get 7 in B1 and Feb-79 in C1 where I want 7 and 2-79 respectively.
I formatted the destination cells as text, but it not worked. Then I formatted the whole sheet as text, but no change in result.
Please help me.
Edit: While using Convert text to columns wizard, I tried changing column data format from "general" to "text" too.
I just tried it and you have to actually select the column with the 2-79 (step 3 of the wizard) and then fill the radio button that says text. If you only do it to the first column then you wont affect the one that's converting to a date.
Feb-79 is correct. Feb-79 = 2/79.
if you would like a string of text you can make
C1=Feb-79
D1=MONTH(C1)&"/"&RIGHT(YEAR(C1),2)
D1=2/29
or if you want to preserve the date value; right click on the range (cells or column) and Format Cells> Number tab > Custom category > Type: "m/yy" without ""
or you can do this
C1=Feb-79
D1=TEXT(C1,"m/yy")
D1=2/29
To get the same effect
Hope this helps.

Converting datetime format to text format in excel

I have an excel file which has data like "04 17" (right aligned) but the format is showing as DateTime i.e 4/1/2017.
My C# Production code is written in such a way that it recognizes if that is mentioned as text format (left aligned).
In the below screenshot all data in "Project Start Date" column need to be left aligned (like I manually wrote in 3rd line).
I am new to excel & macro, please give some clue how to convert these values. I have around 6000 lines, so cant re enter all the columns manually.
Set "Custom" format on column S, enter "MM YY" in the 'Type' slot (without the quotes) ... then set left alignment for the whole column from the menu.
If you need the text version, enter this formula in an adjacent column, let's say column T, row 6:
=TEXT(S6,"MM YY")
Extend the formula in the column to fill the 6000 row range. You can optionally lock in the text values by copying the column and then doing a 'Paste Special - Values' into a new column.

excel 2013 convert column data format from 'yyyymmdd hhmm' to yyyy-mm-dd

How can i convert in excel 2013 column data format from 'yyyymmdd hhmm' to yyyy-mm-dd
Click on any cell in the column and run this macro:
Sub DateFormat()
With ActiveCell.EntireColumn.Cells
.NumberFormat = "yyyy-mm-dd"
End With
End Sub
Firstly, click on the top of the column to select all of the cells within that column, then right click on a random cell within that column and click 'Format Cells', from here a box will show up.
The box will have all different format rules, and by default it should be on the 'Number' tab within the box, from here select 'Date' and then you will be able to select the appropriate type of date format from here that you wish to have.
For your case you should see one corresponding to your yyyy-mm--dd format
If it is text-to-text: =LEFT(A1,4)&"-"&MID(A1,5,2)&"-"&MID(A1,7,2) (split and rejoin the string)
If it is date-to-text: =TEXT(A1,"yyyy-mm-dd")
If it is text-to-date, make a date with: =DATE(LEFT(A1,4),MID(A1,5,2),MID(A1,7,2)) (split the string and give the parts to the DATE function) ...
... to show date type cells in a different format, use methods above (if you don't have yyyy-mm-dd in your "Date" options, you can type it in under "Custom")

Excel Date Conversion from yyyymmdd to mm/dd/yyyy

I have been searching for about an hour on how to do this in Excel.
I have an Excel file that was created from an old system and I am pulling information from a SQL Server Database, I will be inputting the information back into the SQL Server Database and would like the Dates to match.
I have tried Creating a Custom Format, but I am unsure if I even did it Correctly. I found several places where they want to go the other way mm/dd/yyyy to yyyymmdd but they have not been helpful.
I am unfamiliar with using VBA in any Microsoft Products otherwise I am sure that this would be a simple Task.
I have two separate columns that need to be changed.
How do I Format the entire column from (float)yyyymmdd to a (Date)mm/dd/yyyy
You can convert the value to a date using a formula like this, next to the cell:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))
Where A1 is the field you need to convert.
Alternatively, you could use this code in VBA:
Sub ConvertYYYYMMDDToDate()
Dim c As Range
For Each c In Selection.Cells
c.Value = DateSerial(Left(c.Value, 4), Mid(c.Value, 5, 2), Right(c.Value, 2))
'Following line added only to enforce the format.
c.NumberFormat = "mm/dd/yyyy"
Next
End Sub
Just highlight any cells you want fixed and run the code.
Note as RJohnson mentioned in the comments, this code will error if one of your selected cells is empty. You can add a condition on c.value to skip the update if it is blank.
Do you have ROWS of data (horizontal) as you stated or COLUMNS (vertical)?
If it's the latter you can use "Text to columns" functionality to convert a whole column "in situ" - to do that:
Select column > Data > Text to columns > Next > Next > Choose "Date" under "column data format" and "YMD" from dropdown > Finish
....otherwise you can convert with a formula by using
=TEXT(A1,"0000-00-00")+0
and format in required date format
Here is a bare bones version:
Let's say that you have a date in Cell A1 in the format you described. For example: 19760210.
Then this formula will give you the date you want:
=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2)).
On my system (Excel 2010) it works with strings or floats.
for converting dd/mm/yyyy to mm/dd/yyyy
=DATE(RIGHT(a1,4),MID(a1,4,2),LEFT(a1,2))
Found another (manual) answer which worked well for me
Select the column.
Choose Data tab
Text to Columns - opens new box
(choose Delimited), Next
(uncheck all boxes, use "none" for text qualifier), Next
use the ymd option from the Date dropdown.
Click Finish

Add common prefix to all cells in Excel

I have a column with some text in each cell.
I want to add some text, for example "X", at the start of all cells. For example:
A B
----- >>>> ----
1 X1
2 X2
3 X3
What is the easiest way to do this?
Type this in cell B1, and copy down...
="X"&A1
This would also work:
=CONCATENATE("X",A1)
And here's one of many ways to do this in VBA (Disclaimer: I don't code in VBA very often!):
Sub AddX()
Dim i As Long
With ActiveSheet
For i = 1 To .Range("A65536").End(xlUp).Row Step 1
.Cells(i, 2).Value = "X" & Trim(Str(.Cells(i, 1).Value))
Next i
End With
End Sub
Select the cell you want to be like this,
Go To Cell Properties (or CTRL 1)
under Number tab
in custom
enter
"X"#
Select the cell you want to be like this, go to cell properties (or CTRL 1) under Number tab in custom enter "X"#
Put a space between " and # if needed
Select the cell you want,
Go To Format Cells (or CTRL+1),
Select the "custom" Tab, enter your required format like : "X"#
use a space if needed.
for example, I needed to insert the word "Hours" beside my numbers and used this format : # "hours"
Enter the function of = CONCATENATE("X",A1) in one cell other than A say D
Click the Cell D1, and drag the fill handle across the range that you want to fill.All the cells should have been added the specific prefix text.
You can see the changes made to the repective cells.
Option 1:
select the cell(s), under formatting/number/custom formatting, type in
"BOB" General
now you have a prefix "BOB" next to numbers, dates, booleans, but not next to TEXTs
Option2:
As before, but use the following format
_ "BOB" #_
now you have a prefix BOB, this works even if the cell contained text
Cheers, Sudhi
Michael.. if its just for formatting then you can format the cell to append any value.
Just right click and select Format Cell on the context menu, select custom and then specify type as you wish... for above example it would be X0. Here 'X' is the prefix and 0 is the numeric after.
Hope this helps..
Cheers...
Go to Format Cells - Custom. Type the required format into the list first. To prefix "0" before the text characters in an Excel column, use the Format 0####. Remember, use the character "#" equal to the maximum number of digits in a cell of that column. For e.g., if there are 4 cells in a column with the entries - 123, 333, 5665, 7 - use the formula 0####. Reason - A single # refers to reference of just one digit.
Another way to do this:
Put your prefix in one column say column A in excel
Put the values to which you want to add prefix in another column say column B in excel
In Column C, use this formula;
"C1=A1&B1"
Copy all the values in column C and paste it again in the same selection but as values only.
Type a value in one cell (EX:B4 CELL). For temporary use this formula in other cell (once done delete it). =CONCAT(XY,B4) . click and drag till the value you need. Copy the whole column and right click paste only values (second option).
I tried and it's working as expected.

Resources