[英]How to make cell color as fill color which is done by conditional formatting in MS Excel 2010 - VBA?
我研究了很多,只發現了一些腳本。 我在Microsoft Excel 2010中需要幫助。
我有一個軟件生成的Excel工作表。 它具有使用條件格式設置的單元格顏色,我希望該顏色像單元格的填充色一樣是永久性的。 如何在MS Excel 2010中實現此目標。
使用此vba子將使單元格顏色匹配單元格N3。 您可以更改條件,例如大於,小於等。
Private Sub cmdSelectValues_Click()
Dim MyInput<br>
MyInput = Range("N3").Value
Cells.FormatConditions.Delete
Cells.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=" & MyInput
Cells.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = RGB(255, 255, 0)
End With
End Sub
在Excel 2010+中,您可以遍歷單元格,使用DisplayFormat.Interior.Color
查找CF顏色,並將Interior.Color
設置為該值,然后刪除所有CF。
Sub CopyCfFills()
Dim rng As Range, c As Range
'Get all cells with CF: `On Error Resume Next` ignores error if no cells
On Error Resume Next
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeAllFormatConditions)
On Error GoTo 0
'...or a specific range
Set rng = ActiveSheet.Range("AO7:AY43")
If rng Is Nothing Then
MsgBox "No CF on this sheet!"
Else
For Each c In rng.Cells
c.Interior.Color = c.DisplayFormat.Interior.Color
c.FormatConditions.Delete
Next c
End If
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.