问题描述
我浏览了下面链接中设置的示例
Make conditional formatting static
似乎该代码不再适用于Office19。我是唯一面临代码问题的人吗?或者我做错了什么吗?
设置objFormatCondition = rgeCell.FormatConditions(iconditionscount)
预先感谢您的帮助
avatar = avatar
解决方法
请尝试下一个更简单的方法。选择一个条件格式的单元格并运行下面的代码:
Sub testStaticCelFormatFromCondForm()
With ActiveCell
.Interior.Color = .DisplayFormat.Interior.Color
.Font.Color = .DisplayFormat.Font.Color
.Font.Bold = .DisplayFormat.Font.Bold
.Font.Italic = .DisplayFormat.Font.Italic
.Borders(xlEdgeLeft).Weight = .DisplayFormat.Borders(xlEdgeLeft).Weight
.FormatConditions.Delete
End With
End Sub
或将其用于选定范围内的所有单元格:
Sub RangeStaticCelFormatFromCondForm()
Dim rng As Range,cel As Range
Set rng = Selection
For Each cel In rng
With cel
.Interior.Color = .DisplayFormat.Interior.Color
.Font.Color = .DisplayFormat.Font.Color
.Font.Bold = .DisplayFormat.Font.Bold
.Font.Italic = .DisplayFormat.Font.Italic
.Borders(xlEdgeLeft).Weight = .DisplayFormat.Borders(xlEdgeLeft).Weight
End With
Next
rng.FormatConditions.Delete
End Sub
后一种情况适用于单个单元格条件,但是条件格式化将在所有范围的最后删除,因此不会丢失任何内容...
,感谢您对代码的帮助。
利用我掌握的基本知识以及@faneduru 等用户的帮助,我已经能够调整代码以使其更快。谢谢大家的帮助。如有任何反馈,请告诉我
请找到以下代码-
Sub FreezeConditionalFormattingOnSelection()
Dim Rng As Range,cel As Range,rng2 As Range
On Error GoTo Step102
Step101:
Set Rng = Application.Selection
Set Rng = Application.InputBox(Prompt:="Select range to check for conditional formatting",Title:="Select range",Default:=Rng.Address,Type:=8)
If Rng.Rows.Count < 2 Or Rng.Columns.Count < 2 Then
MsgBox "Please select a range containing more than 2 cells. Reselect range!!",vbCritical,"Range selection error"
GoTo Step101
End If
Set rng2 = Rng.Cells.SpecialCells(xlCellTypeAllFormatConditions)
For Each cel In rng2
With cel
.Interior.Color = .DisplayFormat.Interior.Color
.Font.Color = .DisplayFormat.Font.Color
.Font.Bold = .DisplayFormat.Font.Bold
.Font.Italic = .DisplayFormat.Font.Italic
End With
Next
Rng.FormatConditions.Delete
Exit Sub
Step102:
MsgBox "No conditional formatting cells found in selected range.",vbInformation,"No conditional formats found"
End Sub