如何在公式中仅放置左或右$

时间:2019-04-23 21:59:52

标签: excel vba formula

我想创建一个宏,如果有公式,则将$放在单元格中 但现在我只能同时为这两种方式做,例如A2 ---> $ A $ 2, 如何修改我的代码以仅选择左或右符号? 谢谢!

这是我的代码

    Private Sub CommandButton3_Click()
'Absolute Fomula'
Dim c As Variant
Application.ScreenUpdating = False
For Each c In Selection
    If c.HasFormula = True Then
        c.Value = Application.ConvertFormula(c.Formula, xlA1, , xlAbsolute)
    End If
Next c
Application.ScreenUpdating = True
End

1 个答案:

答案 0 :(得分:3)

请参阅:

https://docs.microsoft.com/en-us/office/vba/api/excel.xlreferencetype

xlAbsolute的替代方法

Name                Value   Description
xlAbsolute          1       Convert to absolute row and column style.
xlAbsRowRelColumn   2       Convert to absolute row and relative column style.
xlRelative          4       Convert to relative row and column style.
xlRelRowAbsColumn   3       Convert to relative row and absolute column style.