简体   繁体   English

VBA 将我的十进制数转换为公式分隔符

[英]VBA convert my decimal number to formula separator

I try to make a formula in vba and I have a problem.我尝试在 vba 中创建一个公式,但遇到了问题。 For example in cell C2 I have a decimal number "4,62" and when I try to use it in a formula, VBA take the comma as a separator.例如,在单元格 C2 中,我有一个十进制数“4,62”,当我尝试在公式中使用它时,VBA 将逗号作为分隔符。

VBA Code: VBA 代码:

Sheets("Feuil4").Range("C3").Formula = "=SUM(" & Range("C2") & ",[@[Prix total ens]])"

If @[Prix total ens] = 5, the final result will be 71 (4+62+5).如果@[Prix total ens] = 5,则最终结果将是 71 (4+62+5)。 How can I make the comma read as a comma and not a separator ?如何将逗号读作逗号而不是分隔符?

Btw I'm French so I know that for most of you, you will written 4.62 Thanks.顺便说一句,我是法国人,所以我知道对你们中的大多数人来说,你会写 4.62 谢谢。

You can change your list seperator from windows regional settings.您可以从 Windows 区域设置更改列表分隔符。

Control Panel > Regional and Language Options > Regional Options Tab.控制面板 > 区域和语言选项 > 区域选项选项卡。 > Customize / Additional settings > Type a new separator in the "List separator" box. > 自定义/附加设置 > 在“列表分隔符”框中键入新的分隔符。 > OK > OK > 好 > 好

Reading a decimal number from Excel and using it in VBA is quite a pain, if the Excel uses comma as a decimal separator (German and French Excel).如果 Excel 使用逗号作为小数点分隔符(德语和法语 Excel),则从 Excel 读取十进制数并在 VBA 中使用它是一件非常痛苦的事情。

The work around I have developed is the following function:我开发的解决方法是以下功能:

Public Function ChangeCommas(ByVal myValue As Variant) As String
    
    Dim temp As String    
    temp = CStr(myValue)
    ChangeCommas = Replace(temp, ",", ".")
    
End Function

In your case:在你的情况下:

Sheets("Feuil4").Range("C3").Formula = "=SUM(" & ChangeCommas(Range("C2")) & ",[@[Prix total ens]])"

Sheets("Feuil4").Range("C3").Formula = "=SUM(C2,[@[Prix total ens]])"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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