VBA不能将磅符号添加到值
我有这个macros打印每个工作完成的时间,但是当我尝试添加每个人的收费率这个作品,
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"
的行,并返回一个错误也。 我错过了明显的东西吗? 谢谢
要创build一个string使用类似于:
Sub StringMaker() Dim price As Double price = 12.5 With ActiveCell .Offset(0, 5).Value = "£" & price End With End Sub
并创build一个格式化的数字使用类似于:
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