Change Cell Reference between Absolute and Relative

后端 未结 2 2059
眼角桃花
眼角桃花 2021-01-07 11:03

I want to write a macro which goes through all cell references in a selection\'s cells formula and changes them to absolute or rela

2条回答
  •  一个人的身影
    2021-01-07 11:29

    You can use ConvertFormula method.

    4th Parameter determines whether its absolute or not. 1 sets it to absolute and 4 sets it to relative. As per one comment to this answer, if you are looking for mixed references, then its bit complex. but reading your question and comments, I think that's not what you are after.

    Examples:
    '/ Set it to absolute
    ActiveCell.Formula = Application.ConvertFormula(ActiveCell.Formula, xlA1, xlA1, 1)
    
    '/ Set it to relative
    ActiveCell.Formula = Application.ConvertFormula(ActiveCell.Formula, xlA1, xlA1, 4)
    

提交回复
热议问题