I am trying to apply Persian date format in text boxes inside some worksheet.
The Text boxes now stores the date in format "dd/mm/yyyy hh:mm" And that's a thing that i applied by myself.
But i'm struggling with applying Persian date in these text boxes. I recorded some macro when i'm changing date format of cell to Persian, and i was trying to use it on text box but this code does not seem to work properly.
This is code that i'm using now and it is working properly
TextBox1 = Format(TextBox1, "dd/mm/yyyy hh:mm")
and those lines I was trying to use to apply Persian date but I don't get any effect
TextBox3 = Format(TextBox3, "[$-fa-IR,16]dd/mm/yyyy;#")
And this is the effect of recording macro and changing date format to Persian manually. From this line i got a formula and try to implement it above.
Range("J30").Select
Selection.numberFormat = "[$-fa-IR,16]dd/mm/yyyy;#"
Does any of you could provide me with some reasonable solution to this?
Thank you in advance for your Help.
This blog post should be of help to you as it covers a number of different date formats, including Persian https://www.jquery-az.com/3-ways-change-date-format-excel-14-date-formulas/
In excel, the following formula will format a standard date in Persian:
=TEXT(A1,"[$-0429]mmmm d,yyyy")
So in VBA, the following should work:
Range("J30").numberFormat = "[$-0429]mmmm d, yyyy"
In terms of formatting within a text box, providing the textbox text is referring to a cell location, formatting this cell location will impact on the format of the textbox - see illustration below.
If you are trying to format text directly within the textbox you might try adding .value to your code snippet above eg.
TextBox3.value = Format(TextBox3.value, "[$-fa-IR,16]dd/mm/yyyy;#")
I only have access to Office for Mac at work and that feature is not supported for me to test.
This blog post discusses how to apply formatting to text boxes via VBA but it may not support language formatting options. If thats the case you may consider amending your text boxes to reference a cell location that you can format.
https://www.extendoffice.com/documents/excel/4899-excel-format-textbox-as-currency.html
Have you installed Persian?
File > Options > Language > [Add additional editing languages] - Select Persian > Add > OK
You will probably need to restart Excel and may need to re-apply the formatting.
Related
I would like to build a piece of code which can convert numbers in my workbook from English to French number formatting.
For example,
English formatting would be $1,000,000.99, and
French would be 1 000 000,99 $
I can not seem to find any default French codes built into excel and using a , instead of a . for the decimal does not show numbers less than $1.
Any assistance or advice is appreciated!
To make the currency symbol appear to the right of your numbers, use the NumberFormat property of a Range object and set it to:
For dollars: #,##0.00 [$$-C0C]
For euro: #,##0.00 [$€-C0C]
The behavior of commas and periods for decimals and digit grouping is usually controlled by your Region and Language Settings in Windows.
You can change this setting application-wide (i.e. it will affect any workbook opened on your machine) by changing the values of Application.DecimalSeparator and Application.ThousandsSeparator in VBA. Alternatively, you can achieve the same effect by going to File > Options > Advanced and uncheck "Use system separators"
To get the code for any action in Excel:
start recording a macro
do what you want to replicate via code
stop the recording
check the macro code (ALT+F11)
In this case applying the formatting gives this code:
Selection.NumberFormat = "#,##0.00 $"
Hope this helps.
I must write mm-aaaa (06-2014 for example) in an Excel sheet, but each time I do so, Excel automatically changes my cell format to "personalised" and select a date format.
Writing the value and pressing enter changes the format to custom; changing the format back to General change the date to 41780, which is no good either.
I absolutely need to keep the "General" format and the date to be written as mm-aaaa because the file is then going to be read by a python script which I cannot change. How can I achieve this?
Special pasting as text didn't work.
However setting the cell format as text, writing in it then changing it back to standart worked
I am using Microsoft Excel 2010. In that after entering the values for example if i enter "01234" and give enter it changes to "1234". The "0" is getting eliminated. To solve this issue i ll do the following procedure
Right click on the cell --> format cells --> Number Tab --> choose Text in category column.
I hate this process to do often. Is there any solution to predefine it meaning it should always be in "text" whenever i open a new workbook.
You can refer to this link to do what you want:
http://www.pchelps.com/2011/03/productivity-101-setting-up-excel-default-formatting/
Basically, open a workbook and format it in the way you want. Then save that as your template.
An alternative to making your format Text is to use custom formatting. For example if you know that your number will always have 5 digits (sometimes with leading 0s), you can do a custom format with 00000.
In this way, even when you enter manually 123 into the cell, it will be formatted as 00123
I have a .xls I need to convert to .csv
The file contains some date columns. The format on the date is "*14/03/2001" which, according to Excel means the date responds to regional date and time settings specified for the OS.
Opening in Excel you see:
20/01/2013
01/05/2013
Save as... CSV
Open in notepad:
01/20/2013
05/01/2013
I have temporarily fixed by setting date formats to "14/03/2001" (no *) but even some other custom formats with no *, like "d/mm/yyyy h:mm" get mangled when saved to CSV.
Although keeping this in mind http://xkcd.com/1179/
In the end I decided to use the format YYYYMMDD in all CSV files, which doesn't convert to date in Excel, but can be read by all our applications correctly.
You can save your desired date format from Excel to .csv by following this procedure, hopefully an excel guru can refine further and reduce the number of steps:
Create a new column DATE_TMP and set it equal to the =TEXT( oldcolumn, "date-format-arg" ) formula.
For example, in your example if your dates were in column A the value in row 1 for this new column would be:
=TEXT( A1, "dd/mm/yyyy" )
Insert a blank column DATE_NEW next to your existing date column.
Paste the contents of DATE_TMP into DATE_NEW using the "paste as value" option.
Remove DATE_TMP and your existing date column, rename DATE_NEW to your old date column.
Save as csv.
Change the date and time settings for your computer in the "short date" format under calendar settings. This will change the format for everything yyyy-mm-dd or however you want it to display; but remember it will look like that even for files saved on your computer.
At least it works.
You need to do a lot more work than 1. click export 2. Open file.
I think that when the Excel CSV documentation talks about OS and regional settings being interpreted, that means that Excel will do that when it opens the file (which is in their "special" csv format). See this article, "Excel formatting and features are not transferred to other file formats"
Also, Excel is actually storing a number, and converting to a date string only for display. When it exports to CSV, it is converting it to a different date string. If you want that date string to be non-default, you will need to convert your Excel cells to strings before performing your export.
Alternately, you could convert your dates to the number value that Excel is saving. Since that is a time code, it actually will obey OS and regional settings, assuming you import it properly. Notepad will only show you the 10-digit number, though.
If you use a Custom format, rather than one of the pre-selected Date formats, the export to CSV will keep your selected format. Otherwise it defaults back to the US format
Place an apostrophe in front of the date and it should export in the correct format. Just found it out for myself, I found this thread searching for an answer.
A not so scalable fix that I used for this is to copy the data to a plain text editor, convert the cells to text and then copy the data back to the spreadsheet.
Change the date range to "General" format and save the workbook once, and change them back to date format (eg, numberformat = "d/m/yyyy") before save & close the book. savechanges parameter is true.
You can send your date to excel not like the "date" but like just a "string" with empty space at the start and end of the string.
Your problem is happening due to excel see your '11/02/2023' like a date, but you can hack it and change this date to a simple string like ' 11/02/2023 '.
Old: '11/02/2023'
New (solution): ' 11/02/2023 '
I'm building an Excel xlsx spreadsheet using the office open XML SDK. I can add dates to the sheet by converting them to their "AO" date representation and setting the Cell Value to number. I can't, however, figure out how to add the dd-mm-yy formatting to the cell.
I've seen a lot of complicated examples where you have to create a stylesheet from scratch, add the format to it and then reference that format, but I figure there must be an easier way. I'm creating my sheet from a template, and Excel already has builtin formats/styles. IMO I should be able to just load the stylesheet from the excel file I'm using as a template and then apply the format. Can't figure out how to do it though.
If you're creating an xlsx from scratch you can't avoid creating the style sheet. You minimally need a style sheet and cell format element. The cell format element can reference a built-in date format in which case you can avoid the custom number format, but if you want a date format that isn't built-in you need a number format element too.
If you're creating an xlsx from a template xlsx, then you can reference a cell format that's already defined, but it can be very sensitive since the references are based only on index, so you are safer looking through the defined cell formats to find the one that matches the date format you want as opposed to hard-coding the cell format index.
Try this - I used it when I was trying to make my own number formats. It's a good example:
Advanced Styling in Excel OpenXML
You will still have to create a style sheet but this is a very good place to start. He has quite a few styles in his as he demonstrates what can be done. Your style sheet could be lots simpler if you only want the one format.
Also have a quick look at the list in this post. Your format may be built into Excel already.
Built in Styles for Excel