VBA从文件导入值处理点和逗号(千位和小数)



我在导入来自SAP的txt或csv文件时遇到了问题。在该文件中有具有值的列,其中大多数是整数值,这些没有问题。我面临的问题是有小数的值。例如,我有一个列,其中包含股票值,范围从0,001到99 999,999。由于我在葡萄牙,我的小数/千位区域设置是";对于千千万万的人,对于小数点。我需要将所有导入的值都以相同的格式处理,但是我不能这样做。我尝试了几种解决方案,甚至已经在stackoverflow上的解决方案,但是再次没有成功。我还尝试禁用区域设置,并指定千位分隔符和小数分隔符。还有另一个问题,由于SAP导出这个字段(列)总是有10个字符,我需要替换";对于没有"(没有空格),如果我这样做,其中的值将被视为一个数值,并且已经改变了导入的值。我甚至尝试保留Excel的空格,以便将值视为字符串,并替换点,然后删除空格,但是随后,Excel将点和逗号都检测为点。我不知道它是否有帮助,但如果我在Excel中从菜单中查找和替换,并选择范围,它工作得很好。如果我用这些步骤记录一个宏,然后运行相同的宏,它不工作,我得到相同的奇怪行为和结果。

下面是一些原始值的示例,以及如何导入它们:

Raw Value      Pretended Value
3.655,600      3655,6    (should remove the thousands separator)
10.548         10548     (should remove the thousands separator)
872            872       (once there is no separators, it should do nothing)
1.872          1872      (should remove the thousands separator)
16.000         16000     (should remove the thousands separator)
105,372        105,372   (only decimals separator, it should do nothing)
460,8          460,8     (only decimals separator, it should do nothing)
60,72          60,72     (only decimals separator, it should do nothing)
1.574,400      1574,400  (should remove the thousands separator)
任何建议都会很有帮助。提前感谢,豪尔赫·维埃拉
Columns("M:M").Select
Selection.Replace What:=".", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Columns("M:M").Select
Selection.Replace What:=".", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

3.655,600     3 655 600 (it should be 3655,600)
10.548            10548 (correct)
872                 872 (correct)
1.872              1872 (correct)
16.000            16000 (correct)
105,372          105372 (it should maintain 105,372)
460,8              4608 (it should maintain 105,372)
60,72              6072 (it should maintain 105,372)
1.574,400     1 574 400 (it should be 1574,400)
With ActiveSheet.QueryTables.Add(Connection:= "TEXT; C:TestTest.csv", Destination:=Range("$A$1"))
.TextFileThousandsSeparator = "." 
.TextFileDecimalSeparator = ","