我是使用VBA for Excel的新手,但经过一些搜索没有结果我猜我需要你的帮助。
我正在尝试格式化特定单元格,以便在满足一个条件时,它显示来自另一个单元格的值,但前面是特定文本,例如" Constantin"。因此,显示的结果将是例如Constantin 80.25。
我尝试的代码如下所示:
If Cells(4, 1) < 0 Then
With Range("A1")
.NumberFormat = "'Constantin' 0.00"
.Value = - Cells(4, 1)
End With
End If
我知道语法不对,这是我的问题,我想我找不到合适的语法。我希望我不会因为这个简单的问题而困扰你,但我无法找到我需要的东西。非常感谢
答案 0 :(得分:1)
看起来你不需要这个单词作为实际格式的一部分,在这种情况下这样的东西就足够了:
If Cells(4, 1).Value < 0 Then
Range("A1").Value = "Constantin " & (Cells(4, 1).Value * -1)
End If
如果确实想要使用With
块,那么:
With Cells(4, 1)
If .Value < 0 Then
Range("A1").Value = "Constantin " & (.Value * -1)
End If
End With