Excel VBA:您可以修改现有条件格式规则的范围(使用Sub)吗?

时间:2016-11-04 20:13:35

标签: excel vba excel-vba

我有以下条件,当存在" N"时,会更改第一个工作表上单元格的颜色。在另一个工作表的相应单元格中,称为"要求":

=AND(Requirements!D11="N",D11<>"") 'the second piece of this conditional prevents blank cells from being formatted

我有一个Sub用于在两个工作表中添加一个新列,当我这样做时,新列的单元格引用不对齐。

我想知道是否有办法在我的Sub中添加一些代码,可以重新定义条件格式的范围。我的Sub添加新行如下:

Private Sub CommandButton2_Click()
'Add New Employee

Dim c As Long
c = Selection.Column

Columns(c + 1).Insert Shift:=xlToRight
Range(Cells(1, c + 1), Cells(9, c + 1)).Merge

Sheets("Requirements").Columns(c + 1).Insert Shift:=xlToRight
Sheets("Requirements").Cells(1, c).Copy
Sheets("Requirements").Cells(1, c + 1).PasteSpecial xlPasteFormulas

Application.CutCopyMode = False


End Sub

0 个答案:

没有答案