简体   繁体   English

仅将活动单元格复制和粘贴为值的宏

[英]Macro to copy and paste as values only the active cells

I am new creating macros and I usually record them but I'm having problems copying and paste as values to remove the formula from 3 highlighted cells 我是新创建的宏,通常会记录它们,但是在复制和粘贴值以从3个突出显示的单元格中删除公式时遇到问题

For example I have a formula on cell B3 C3 & H3 so I would like to highlight only those cells manually and then the macro can remove the formula on each like copy and paste as values on the same cells 例如,我在单元格B3,C3和H3上有一个公式,因此我只想手动突出显示那些单元格,然后宏可以删除每个像复制和粘贴一样的公式,并将其粘贴为相同单元格上的值

I have tried with ActiveCell.Select but that only works for 1 cell not for multiple cells and also the problem is that I need to change to values different cells each day 我已经尝试过ActiveCell.Select,但只适用于1个单元格,不适用于多个单元格,而且问题是我每天需要更改为不同的单元格的值

Not sure I follow your question exactly but here is what I think your asking for. 不确定我是否完全遵循您的问题,但这是我想您要提出的问题。

You can loop through each cell that is selected and then set the cell value to it's current value which effectively removes all formulas. 您可以遍历选定的每个单元格,然后将单元格值设置为其当前值,从而有效删除所有公式。 There are other ways to do this but I think this best answers your specific question. 还有其他方法可以做到这一点,但我认为这可以最好地回答您的特定问题。

Sub removeFormula()
    For Each cell In Selection
        cell.Value = cell.Value
    Next cell
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM