首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Application.International xlDecimalSeparator解决方案

Application.International xlDecimalSeparator解决方案
EN

Stack Overflow用户
提问于 2014-12-15 10:37:25
回答 1查看 2.9K关注 0票数 1

我必须从一个单元格中通过copy_paste值创建一个表。然后,这些值将与来自另一个单元格的值相乘。问题是“xlDecimalSeparator”。当它被设置为“。”没事的。当它被使用时,问题就开始了。(我有荷兰的设置)。我试图找到一个解决办法:将单元格声明为文本,然后将",“替换为".",将值放在单元格中,然后将单元格格式化为数字。每件事情都运行得很好,除了最终得到正确的值,我必须双击单元格+ enter才能得到结果公式,否则我只有"=3*$D$1“这样的东西,而不是6(函数的结果)。

所以我的密码是:

代码语言:javascript
复制
Sub Copy_Cell_test()

Dim my_range As Range
Dim strDecimal As String
Dim c As Variant

Application.ScreenUpdating = False

strDecimal = Application.International(xlDecimalSeparator)
If strDecimal = "," Then strDecimal = "."

Set my_range = Worksheets("sheet_test").Range("A2:H111")

    With my_range
        For Each c In my_range
            If Not c.Value = "" Then
                c.NumberFormat = "@"
                c.Value = Replace(c.Value, ",", strDecimal)
                c.Value = "=" & c.Value& & "*$D$1"
                  If Application.International(xlDecimalSeparator) = "," Then
                      c.Value = Replace(c.Value, strDecimal, ",")
                  End If
                c.NumberFormat = "0.00"" €/lm"""
                'c.Value = c.Value <<< Here I have error if "," is set
            End If
        Next c
    End With
    Application.ScreenUpdating = True

End Sub

我怎么才能修好它?我尝试发送键F2 + ENTER,但它不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-15 14:23:01

这对我和FormulaLocal起了作用。

代码语言:javascript
复制
Option Explicit

Sub Copy_Cell_test()
    Dim my_range As Range
    Dim c As Range
    Dim formulaText As String

    On Error GoTo handleErr

    Application.ScreenUpdating = False
    Set my_range = Worksheets("sheet_test").Range("A2:H111")

    With my_range
        For Each c In my_range
            If Not c.Value = "" Then
                formulaText = "=" & c.Value & "*$D$1"
                c.FormulaLocal = formulaText
                c.NumberFormat = "0.00"" €/lm"""
            End If
        Next c
    End With

    Application.ScreenUpdating = True

handleErr:
    If Err.Number = 0 Then Exit Sub
    MsgBox Err.Description
End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27482144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档