vba 数字格式写具体文字

vba number format write specific text

我对使用 VBA 作为 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

我知道语法不对,这是我的问题,我想我找不到正确的语法。我希望我不会用这个可能很简单的问题来打扰你,但我就是找不到我需要的东西。非常感谢

看起来您不需要将单词作为实际格式的一部分,在这种情况下,像这样的内容就足够了:

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