Excel Print number with correct decimal Seperator - excel

I use the print function to export a Cell Value to csv file. I use this macro on several PCs with different Localization Settings. The problem i am experiencing is, that on some PCs the Output is 4,11 and 4.11 on others. Is there any Format Method, that allows me always write a Number with a semicolon as decimal Seperator?

As far as I'm aware, there is no format method for changing the decimal separator. Instead your options are temporarily telling Excel to use a special character or using Replace().
Application.UseSystemSeparators = False
Application.DecimalSeparator = ";"
Print #1, rngValue.Text
Or
Print #1, Replace(rngValue, ",", ";")
In either case you then have a problem, when reading the numbers back in, of converting them back to the correct character so they are considered numbers.
A better question might be how do programmers in places that use the comma as the decimal separator handle decimal values in CSV files?

Related

reading data from excel into SAS and converting character to numeric

I am reading data from an excel file in SAS and inserting the values to an oracle table. The oracle table has a numeric column. If the excel file has numbers, it works fine. But if the column is left blank in the excel file, it is read as a character value and insertion to oracle fails.
Is it possible to convert the column to numeric if its is blank, but read it as is if its has a number?
Thanks!
Let's assume that SAS is reading this column as a character and you cannot convert it directly within the file. This happens sometimes: maybe you don't have authorization to do it, or maybe it's just not working like you're expecting. SAS can go from character to numeric and numeric to character with two functions: input() and put().
Going from Character to Numeric: input()
input() is for changing character data into numbers.
This is great for reading in dates, currency, comma-separated numbers, etc. If you need your data as a number, use this function. Its syntax is:
num_var = input(char_var, informat.);
In your case, let's say we always expect numbers to be here even if it's missing. We'll use the 8. informat for our variable of interest, my_var.
data want;
set have_excel(rename=(my_var = my_var_char) );
my_var = input(my_var_char, 8.);
drop my_var_char;
run;
Note that we need to create a new variable. We rename the variable of interest to something else, then create a new version of the variable of interest that is a number. In SAS, just like many other languages and database systems, when a variable is declared as a character or number, it is always a character or a number.
Going from Numeric to Character: put()
put() is for putting a number to a character or a character to another character.
This is great for converting SAS dates to characters, adding custom formats, converting a character to another character, etc. The syntax is:
char_var = put(num_var, format.);
OR:
char_var = put(char_var, format.);
Note the previous use case: with put(), you can convert characters to other characters. This is very handy for standardizing values or even merging data using a format.
For example: let's convert a number to a comma-separated character number.
data want;
char_number = put(1234, comma.);
run;
Output:
char_number
1,234
Below case statement worked for me.
case
when missing(input(cats(COLUMN_VALUE), best8.)) THEN input(cats(COLUMN_VALUE), best8.)
when not missing(input(cats(COLUMN_VALUE), best8.)) THEN input(cats(COLUMN_VALUE), best8.)
end as COLUMN_VALUE

Uipath overdrives Excel file Locale configuration

I have to process some excel files that comes with an specific Numeric format that is es-CL
that has dots as a thousand separator and comas as decimal separator.
Thousand separator = 100.000.000
Decimal= 1.000.000,1213
When i use any of the excel activities the numbers inside the excel change their format and leaves them like this
Before: 13.640
After:13,64
the thousand separator becomes a coma and the 0 is erased.
I already tried the “Preserve Format” option, replacing the dots with a "" and i get the same result.
Is there a way to change the locale of the excel activities, if it not, what are my options?

How can I make sure Excel does not change number format of a data label in other language versions?

I have a workbook with VBA code that specifies a number format for data labels in a horizontal bar chart.
Chart.SeriesCollection(1).DataLabels.NumberFormat = "0.0"
In my copy of Excel (O365) in English, output is as expected, e.g. 3.7. When the workbook is opened in another copy of Excel (O365) in a language other than English, Excel appears to insert a backwards slash that can be seen in the Format Code -field of the Format Data Labels -sidebar (i.e. 0\.0). Where output should be e.g. 3.7, output becomes 0.4.
The issue persists when I load up the workbook after it has been touched by the non-English Excel - my version doesn't throw away the backward slash. The issue goes away when I delete the backwards slash, and output is as expected again.
It seems to me Excel treats the leading zero and decimal point as plain text and the second zero as the intended numerical character.
How can I make sure Excel maintains the number format specified in VBA when a workbook is opened in a different language version?
Don't have a direct solution, but if this persists with NumberFormat, you can programmatically use combinations of built-in Excel functions to achieve the same numbers.
for ex:
number = Round(number, 1)
In this case, you can leave the NumberFormat as "General" or something similar
It appears the easiest solution is to programmatically disable decimal separators and replace them with your own, as described here.
Application.DecimalSeparator = "."
Application.ThousandsSeparator = ","
Application.UseSystemSeparators = False
I came across this solution in this thread while searching for how to determine the language version of Excel.
Another solution is to use the decimal separator prescribed by the system when defining the number format. This solution seems to also produce the desired result (one decimal place displayed, even if 0), though with whatever decimal separator the system has defined:
Chart.SeriesCollection(1).DataLabels.NumberFormat = "0" & Application.International(xlDecimalSeparator) & "0"

Excel – locale-independent Number Format

I looking for a number format that is locale-independent.
Let's say that I want that my Excel file use an a character as a thousand separator and a b character as a decimal separator on every computer (so this question is not about local Excel settings). The second wish is that the number has always two decimal places.
Can I do this only with a number format without VB code?
After some attempts, I came to this format: ###\a###\a##0\b.00.
1234567.89 > 1a234a567b.89
The problems are:
I must repeat ###\a section and I can not get rid of dot decimal separator (the decimal places are not taken into account without the dot character).
Can I do this only with a number format without VB code?
No.
Even if you can get your separator characters inserted, you will not be able to remove the decimal separator.
The decimal separator is displayed in the cell whenever it is included in custom number display format settings.

Replace "." with "," in Excel 2013

I have an Excel file, generated from database. It contains a column filled with number values that looks like this:
Values:
123,17
1973,27
12124.97
123.09
-234,01
-732.66
My problem is, that Excel finds numbers only when they are used with "," separator. How can I change all the "." to ",", so all values in that column would be recognized as numbers (aligned to right side of column).
Also, I have a lot of those files to maintain, so an automatic procedure would be highly appriciated.
Select the Column and Hit CRTL+H,
Enter '.' in 'Find What' and enter ',' in 'Replace with' and hit 'Replace All' button
Your data sample looks wrong. It's inconsistent.
If your system uses the comma as the decimal separator, then ALL your numbers should use the comma for the decimal.
If your database system uses a dot as the decimal separator, then ALL your numbers should use the dot for the decimal.
The numbers in your example are a random mix of comma and dot as the decimal separator.
You may want to configure your source system to apply the decimal separator in a consistent way.
It's quite inconceivable why your system would use a comma for one value, but use a dot for another value. You may need to get to the bottom of that logic before you can proceed any further.
Possibly, the "numbers" are really text values from other data sources that use either comma or dot for the decimal separator.

Resources