仅自动将颜色从一个单元格复制到另一个单元格 - EXCEL VBA

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22228879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:55:33  来源:igfitidea点击:

Copy automatically only the color from one cell to another- EXCEL VBA

excelvbaexcel-vbacolors

提问by CreamStat

I have cell 017, the value and color of this cell is changing constantly due to a formula and conditional formatting.

我有 cell 017,由于公式和条件格式,该单元格的值和颜色不断变化。

Cell O16changes constantly due to a formula too but the formula and their values are different from cell 017.

单元格O16也会因公式而不断变化,但公式及其值与单元格不同017

What I want is that cell O16contains the same color of cell O17automatically once the value of cell 017has changed.

我想要的是,一旦O16单元格O17的值017发生变化,单元格就会自动包含相同颜色的单元格。

There should be a solution in VBA. I hope your help.

VBA中应该有解决方案。我希望你的帮助。

EDIT:

编辑:

User simocohas came up with a solution for Excel 2010 and later:

用户simoco提出了适用于 Excel 2010 及更高版本的解决方案:

Private Sub Worksheet_Calculate()
    Range("O16").Interior.Color = Range("O17").DisplayFormat.Interior.Color
End Sub

Unfortunately I use Excel 2007, Is there and equivalent to that code in 2007?.

不幸的是,我使用 Excel 2007,是否有和 2007 中的代码等效?。

回答by Dmitry Pavliv

Works only with Excel 2010 and later

仅适用于 Excel 2010 及更高版本

If your cell O17can be changed only through formula, use following code (this code should be used in Sheetmodule):

如果您的单元格只能通过公式O17更改,请使用以下代码(此代码应在模块中使用):Sheet

Private Sub Worksheet_Calculate()
    Range("O16").Interior.Color = Range("O17").DisplayFormat.Interior.Color
End Sub

Otherwise, also add Worksheet_Changeevent with the same code.

否则,也添加Worksheet_Change具有相同代码的事件。