简体   繁体   中英

Pasting decimal numbers in excel / comma and point decimal separator

I want to get data into excel using DDE. I get an new value every second from the DDE and use a macro to store every value in the next row. So for so good.

Problem is the decimal separator.

I get from the DDE a value like -5.18834 Using the macro or pasting it into excel, the value shows -518.557 but the actual value is -518557. The decimal point gets wrongly interpreted by excel. When I paste the same value in notepad I get correct value ie -5.18557 I tried deviding the value by 10000 in excel, but some values are 5 numbers instead of 6, so then it's wrong again.

I tried formatting cells, changing decimal separator in excel's options, changed regional setting on my pc but none of those work. I also tried adding TextFileDecimalSeparator = "." in the macro (found on this website) but that doesn't work either. Processing the data after the macro has finished is not an option.

Thanks for any help.

Your enumeration, of what you have tried already, seems to rule this out, but i would be very bewildered if the following not would work:

Application.DecimalSeparator = "."
Application.ThousandsSeparator = ","
Application.UseSystemSeparators = False

' here do your paste

Application.UseSystemSeparators = True

I had a similar problem - decimal numbers that I passed with macro into cells were assumed by excel as text... So I tried exactly same procedures as well as you did...Didn't help... I tried even the solution mentioned above...it didn't help either. It's a great solution though. Unfortunately it wasn't useful in my case, macro simply ignored this and used other seperator instead. I tried many things and I felt desperate and then I came with this clumsy solution:

  Cells.Replace What:=",", Replacement:=".", LookAt:=xlPart, SearchOrder _
    :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Macro ignored the setting for the decimal separator so I decided to replace given separator with right one. It works! Like I said it's clumsy solution but as long as it works...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM