Pasting decimal numbers in excel / comma and point

2019-09-22 01:27发布

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 i.e. -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.

3条回答
Root(大扎)
2楼-- · 2019-09-22 01:52

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
查看更多
看我几分像从前
3楼-- · 2019-09-22 01:58

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...

查看更多
登录 后发表回答