Excel assume dates is in US format - date

I created a macro that copy a column where 02/04/2013 12:35 means 2nd of April
I then paste it and use text to columns to get rid of the time part. Excel for some reason than interpret it as 4th of February. Tried both selecting text at the last step of the text to columns and date but in both cases it get flipped.
Dates that cannot be flipped like 28/03/2013 remains correct.
If I don't use a macro but manually do it Excel doesn't flip the day and month only when running it as a macro that occurs. Noticed it occurs in another macro as well when just copy a cell with a date to another cell with a date.

You could try:
Sub Convert_Dates()
Dim Rng As Range
Set Rng = Selection
For Each c In Rng
c.Value = DateSerial(Right(Split(c)(0), 4), Mid(Split(c)(0), 4, 2), Left(Split(c)(0), 2))
Next c
End Sub
It can also help with "text dates" to use Format and "dd/mmm/yyyy" as this doesn't tend to get mixed up.

Related

How do I change the date format from MM/DD/YYYY to DD/MM/YYYY in libreoffice calc?

I have a spreadsheet with existing date values that I'd like to convert from MM/DD/YYYY to DD/MM/YYYY format. Is there any way of doing this?
The spreadsheet comes from a csv file from someone else that i have opened in calc.
Select the cells with the dates and in Cell -> Format, choose the date format you wish (DD/MM/YYYY)
Making sure the cells are selected, go to Data -> Text to columns choose "Separated by" and "Tab" and click "OK"
Cells should now have the desired format
Cut (or copy then erase) all values from the column (CTRL + X).
Choose Edit -> Paste Special -> Unformatted text (MAJ + CTRL + ALT + V).
On "Fields", click on your column, then select "Date (MDY)". It is important here to select the format the data currently is, NOT the format you want it to be.
If date is still not OK, you will need to follow this additional step (response above from #cybernetic.nomad):
Select the cells with the dates and in Cell -> Format, choose the date format you wish (DD/MM/YYYY).
NB: Note that my LibreOffice Calc is not in english so I am not 100% sure about the option names.
You select the cells to format, then you press Ctrl-1 (or choose "Format" - "Cells..." from the menu, or any other way) to open the dialog to format cells. There is a text field "Format code" where you enter "DD/MM/YYYY" without the quotation marks. Click "OK".
If that does not format the date like you want, the value in the cell is not interpretable as a date. Investigate the cell's value, you might have a text marker (a single apostrophe ') as the first character.
To check this out and experiment with the formats, choose "Insert" - "Date" from the menu. It puts the current date into the current cell.
Disclaimer: Since my Calc is not set to English, the names of menus and their entries might be different. I just guessed how they could be named.
EDIT:
If you can't change the cell format because the date is constantly recognized as "text", you might like to try this:
Insert a column right from the date column. This produces in your case the column O. All columns right of it are pushed to the right.
Put this formula in cell O2 on the right of the first date text:
=CONCATENATE(MID(N2;4;3);MID(N2;1;3);MID(N2;7;4))
It takes snippets (MID()) from cell N2 and concatenates them in the new order. Details of the functions are in Calc's documentation.
You will need to adjust N2 to the correct cell reference if it is not the cell directly left of the cell you're entering the formula.
Put the cell cursor on N2.
Press these key combinations in sequence to mark a deep enough range of cells in column O: Control-Down, Right, Shift-Control-Up. The cell cursor will be on cell O2 now, and the range below and including it is marked.
Now press Control-D to copy the formula in O2 into each cell in the range.
Now you will have a new column O with the text of N, but exchanged characters. The values are still "text", though.
If you like, you can shrink the width of column N now, or hide it.
Example:
Input wanted: DD/MM/YYYY (31/12/2021)
Input accepted: MM/DD/YYYY (12/31/2021)
First add new Date type
Go to Format --> Cells
In "Category" select "Date"
In "Format code" write the input wanted. In this case DD/MM/YYYY
Press the green check
Second format style
Go in the cell where you want to add the date
Write the date in the wrong format. Example: 12/31/2021 (for 31st December 2021) even if you want 21/11/2021
Select that cell and press CTRL-X. The text should disappear
Select that now empty cell and do: Edit -> Paste Special -> Pase unformatted text
The date should be there in the wrong format
Select that cell with the wrong date and do: Format --> Cells
In "category" select "date" and double click on the newly added date type (aka DD/MM/YYYY)

How to format date in libre office

I have a column of dates in a format below:
Fri Dec 25 02:45:23 MYT 2015
Fri Dec 25 17:38:57 MYT 2015
How do I change it to a format as below:
2015-12-25
2015-12-25
I have tried to format cells but it is not working. Any idea ?
At first the Calc must accept those strings as dates. I don't know if any Asian language versions will do that. Default English and German language versions don't.
So at least with default English and German language versions, first there is a need to convert the strings into default date strings.
I've done this with the formula:
=--(LEFT(A1;11)&RIGHT(A1;4)&MID(A1;11;9))
Then applied the format YYYY-MM-DD HH:MM:SS on the cells.
Change column type when opening the file and try to format cells as any format you need.
Assume that dates are in column A.
1. Insert new column B to the left of old column B.
2. In B1, input: =Value(A1)
3. Select B1, right click -> format Cell -> Numbers -> date -> choose the required format
4. Apply this to all column B rows.
5. Select all of column B.
6. Copy all column B cells (with CTRL-C).
7. Select Edit from the menu.
8. Select Past Special from the menu.
9. In the dialog box that opens, unselect formulas, select the desired conditions, and press OK.
10. You can now delete column A.
11. Save ASAP.
If a cell is formatted as text (#) then everything you enter in the cell is treated as text.
You can eliminate all the apostrophes in those cells:
Change the text format in the range to date format.
with Find & Replace:
Find: .*
Replace: &
In more options: mark selected range and regular expressions.
Select the range if not selected.
Replace All.
If the column is text... my LO version has the CALC function DATEVALUE [DATUMWERT in German], which converts a date text string to a date value

How to write the output of a function into a table cell

I am using a macro in LibreOffice Calc sheet that gives date using function "=NOW()+14" into a cell. How can I permanently write the output of the function to the cell so it does not generate new date every time I open the sheet?
Copy the cell. Edit->Paste Special; make sure the "Text" box is SELECTED and the "Formulas" box is NOT. Hit OK. You may need to format the cell as "date" or "time" (otherwise it shows time as a decimal fraction of 24 hours and date as days since December 31, 1899).
Although if you're already using a macro, why don't you calculate the time in the macro and put the time into the cell instead of a formula?
Dim CalcTime : CalcTime = Now + 14
oCell.setString(CalcTime)

Libreoffice/Openoffice Calc - append string to cells

I need to add .jpg at the end of all he cells in one or more columns
9788895249971 into > 9788895249971.jpg
9788867230129 into > 9788867230129.jpg
9788867230273 into > 9788867230273.jpg
9788867230280 into > 9788867230280.jpg
Detailed step-by-step instructions are much appreciated since I am very new to Calc.
Thanks
Do you need to do this once or is this going to be a repeated task every week/month?
If it is something you need to do just once, here is what you can do:
Next (right) to the column where your numbers are open (insert) a new column.
Assuming the following: Numbers are in column A, New column is column B.
In this new column B in the top cell (B1) write:
=A1&".jpg"
Now copy B1 all the way down to the end. In B1 type [Ctrl]+c then Hold [Shift] and hit [PgDn] until the end then press [Ctrl]+v.
Highlight Column B, [Ctrl]+c, then [Edit] [Paste Special] values only (No formula's) this freezes the calculated data.
This is just another option,
just click the function wizard and select concatenate, in that enter which column you want to enter as text1 as and second column in text2. Then when you click OK you will get an concatenated column like below image
so in the C column you will get as a1.jpg.
For those who continue to find this question (as I did):
This can be quickly done using regular expression option of find and replace. (I don't know what version of Calc introduced regex searches, but 6.2.4 has it.)
If you only want to update some non-blank cells on the sheet, select them.
Choose Find and Replace.
On the dialog, fill in the following:
Enter $ for the Find value. ($ means end of line in regex, or in this context end of cell value.)
Enter the desired suffix (.jpg in the question) for the Replace value.
Check Regular Expressions under Other Options
Check Current Selection Only under Other Options if you want to limit to the cells selected in step 1.
Uncheck All Sheets unless that is what you want.
Choose Replace All
This will update the values in-place and does not require any additional columns or formulas.
There's a much more elegant way to do this that doesn't require sacrificing cells just to hold data types, and can be scaled to work with one cell or a large chart range.
Add both pieces of data into the =CONCAT() function
Make sure to use CONCAT instead of CONCATENATE, as `CONCAT accepts cell ranges and is more dynamic.
Open the Function Wizard on the cell in question, and build the following function:
=CONCAT(<your_data>," <suffix>",...)
# Make sure to add a space before the suffix so it appears in the cell.
# You can use this with as many input variables as required letting
# you add as many strings, formulas, or numbers together.
The result should be something like this. In my example, the cell in question is the final value of Ethereum on a balance sheet:
The above example was an easy one, since it was being used as a test, all my summed values were ints, if I had floating point numbers, they would run away to max decimal places (not very pretty).
The function will drag out and expand intelligently to other cells like any other formula.
Adjusting accuracy of floating point values inside a CONCAT function
Sometimes, adding a cell results in a rounding problem, or an extreme amount of decimal places. You can further nest your function using ROUND(<your_data>,<decimal_places>)
Your function would look like this:
=CONCAT(ROUND(<cell_range>, ".jpg")
In your specific case, you don't need a space in the second argument as you want to append .jpg directly to the end of the string.
`
Using Macros to automate the entire process
This is extremely repeatable, and using the Macros feature, you can automate these to make much more simplified functions that allow you to enter just the variables you need, while the macro does the work in the background.
Based on Emmanuel Angelo R.’s answer, I would advice learning to differentiate between fixed cell references and dynamic ones. The following applies:
Cell A1 contains the suffix you would like to add, e.g. ‘.jpg’
Row 2 contains headings, e.g. B2 = ‘Old Filename’ and ‘New Filename’
Cells A3:A¹ contain your filenames
Cells B3:B contain you concatenation formula
In cell B3, type =concatenate(A3;$a$1).² If your locale requires comma as separator, replace my semicolons with commas. Copy cell B3 by selecting it and pressing Ctrl + C. Move the cursor to cell A3, press Ctrl + ↓ (down arror on your cursor keys); this will move you to the bottom of the list of file names. Move your cursor right, then press Ctrl + Shift + ↑; this will select all cells up to the last cell with contents (the one you just wrote your formula in). Press Ctrl + V to paste your contents.
Adding dollar signs in front of your row/column coordinates, will lock that coordinate when pasted. Say you had a list of file types in cells b1–z1 (e.g. jpg, jpeg, tga, bmp, png et c.). An easy way to create the formula would then be by first typing it in cell B3 as =concatenate(A3;B$1), then paste it to every cell till the end of your file names list (cell z3); these cells would then read …A3;b$1, …A3;C$1 et c. When copying it for all the rows below
You could select the entire range of cells with formulas in row 3 and run a search and replace, replacing all instances of ‘A3;’ by ‘A3;$’, effectively inserting a dollar in front of all the cell references, allowing you to, should the need arise, copy it horizontally as well as vertically (the latter being covered by the $ in front of 1).
¹ This means cells from A3 and however far down your sheet goes
² Strictly speaking, it is only necessary to type it as a$1.

Auto format numbers in org-mode spreadsheets

Is there any way to automatically force number of decimal places in an org-mode spreadsheet? So that 42 would be changed to 43.00 when I move to the next field?
Also, is there automatic formatting for thousands separators?
If you want a field to auto-format when changing to the next one, you would need to use the auto-update row header # to indicate that fields in that row should auto-calc whenever TAB S-TAB or RET are pressed in that row (see Org-Manual).
Then if you include as a formula for that cell (I'm assuming that if you are wanting to enter the value manually you will not have a formula affecting that cell usually) that contains (for your 42 -> 42.00 example)
=$0;%.2f
Information before the = sign can be cell or column references depending if you want the formula to be applied to a single cell or to the entire column. (This is mentioned here)
I wasn't able to find any reference to thousands separators in org, it might not be possible at the moment.
This link on Formula Syntax for Calc shows the various options for org-calc-default-modes, which will allow you to change the display format and precision.
Does this help you in any way?
(setq org-calc-default-modes '(calc-internal-prec 12
calc-float-format (float 9)
calc-angle-mode deg
calc-prefer-frac nil
calc-symbolic-mode nil
calc-date-format (YYYY "-" MM "-" DD " " Www (" " HH ":" mm))
calc-display-working-message t))