使用visual basic更改包含currecny的单元格的数字格式

时间:2017-04-27 06:56:29

标签: excel vb6

我想将其类型的货币值添加到Excel工作表。我为此创建了以下代码片段。

Public Sub WorkSheetForCurrencies(ByRef ProductsCollection As VBA.Collection, ByRef cur As String, ByRef ExgRate As Double, ByRef symbol As String)

Dim index As Long
Dim objProduct As Product

index = 2
For Each objProduct In ProductsCollection

    If symbol = "£" Then
    'Way 01:
        mobjCSVWorkSheet.Cells(index, 8).NumberFormat = "-[$£-809]* #,##0.00_-;-[$£-809]* #,##0.00_-;_-[$£-809]* " - "??_-;_-@_-"
    ElseIf symbol = "$" Then
    'Way 02:
        mobjCSVWorkSheet.Cells(index, 8).Select
        Selection.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* " - "??_);_(@_)"
    ElseIf symbol = "€" Then
        mobjCSVWorkSheet.Cells(index, 8).NumberFormat = "_([$€-2] * #,##0.00_);_([$€-2] * (#,##0.00);_([$€-2] * " - "??_);_(@_)"
    End If

    mobjCSVWorkSheet.Cells(index, 8) = objProduct.SalesUnitPrice * CCur(ExgRate)
    index = index + 1
Next objProduct
End Sub

我已尝试过两种方法来更改数字格式,如上面的代码所示。但那些会给出类型不匹配错误。请告诉我必须更改的内容才能更改单元格编号格式。 谢谢

1 个答案:

答案 0 :(得分:1)

这是你的问题:

Set<JobKey> getJobKeys(NameMatcher<JobKey> matcher) throws SchedulerException;

评估为

"-[$£-809]* #,##0.00_-;-[$£-809]* #,##0.00_-;_-[$£-809]* " - "??_-;_-@_-"

减去

"-[$£-809]* #,##0.00_-;-[$£-809]* #,##0.00_-;_-[$£-809]* "

由于您正在对字符串执行算术运算,因此它会尝试将两边都转换为数值,然后失败。

尝试加倍双引号,例如

"??_-;_-@_-"