VBA无法为价值添加英镑符号

时间:2014-08-22 12:59:04

标签: excel vba excel-vba

我有这个宏打印每个工作完成的小时数,但当我尝试添加每个人的收费率时,这是有效的,

Dim name As Range
Dim nameRange As Range
Dim hours As Range
Dim price As Range

Set nameRange = Range("I:I")
Set name = Sheets("Home").Range("B12").Offset(i, 0)
Set price = Sheets("Home").Range("B12").Offset(i, 1)
Set hours = Range("G:G")

If Not IsEmpty(name) Then
With ActiveCell
    .Value = "Total No. of chargeable hours by " + name
    .Offset(0, 4).Value = Application.WorksheetFunction.SumIfs(hours, nameRange, name)
    .Offset(0, 5).Value = price
End With
ActiveCell.Offset(2, 0).Select
End If
Next i

然而,当我改变

.Offset(0, 5).Value = price

.Offset(0, 5).Value = "£" + price

我收到错误,

我尝试将.Style = "Currency"添加到该行,并且还会返回错误。我错过了一些明显的东西吗?感谢

1 个答案:

答案 0 :(得分:1)

要创建 String ,请使用以下内容:

Sub StringMaker()
Dim price As Double
price = 12.5
With ActiveCell
    .Offset(0, 5).Value = "£" & price
End With
End Sub

并创建格式化数字使用类似:

Sub NumberFormatter()
Dim price As Double
price = 12.5
With ActiveCell
    .Offset(0, 5).Value = price
    .Offset(0, 5).NumberFormat = "£" & "General"
End With
End Sub