我有一个子例程,它在工作表“源”中逐个单元格地获取条件格式属性,并将它们应用到同一工作簿的工作表“结果”中。仅当我得到 Font.Color 和 Font.TintAndShade 时它才能正常工作,它返回 null,因此在结果表中,所有条件格式都具有黑色字体颜色。(您可以在结果表条件格式 > 管理规则中检查它)。
错误是“无效使用 Null”可能是因为值的类型。
这里发生错误:
FCFontC = Xarr(I, J).FormatConditions(II).Font.Color
FCFOntT = Xarr(I, J).FormatConditions(II).Font.TintAndShade
这是我的代码:
Sub FormatCondition1()
Dim FC As FormatCondition
Dim FCFontC As Long
Dim FCFOntT As Integer
Dim FCC As Long
Dim FCT As Integer
Dim II As Integer
Dim Wks1 As Worksheet, Wks2 As Worksheet
Dim Xarr As Range, Yarr As Range
Dim I As Integer, J As Integer
'Dim K As Integer, L As Integer
Worksheets("Source").Activate
Worksheets("Result").Select
Set Yarr = Worksheets("Result").Range("A1:C2")
Yarr.Range("A1:C2").Clear
Set Wks1 = ActiveWorkbook.Worksheets("Source")
Set Wks2 = ActiveWorkbook.Worksheets("Result")
Set Xarr = Wks1.Range("A1:C2")
Set Yarr = Wks2.Range("A1:C2")
For I = 1 To Xarr.Rows.Count
For J = 1 To Xarr.Columns.Count
If Xarr(I, J).FormatConditions.Count > 0 Then
For II = 1 To Xarr(I, J).FormatConditions.Count 'II number of conditions
Set FC = Xarr(I, J).FormatConditions.Item(II)
'cell font formatting
'**** Error is HERE *******
FCFontC = Xarr(I, J).FormatConditions(II).Font.Color
FCFOntT = Xarr(I, J).FormatConditions(II).Font.TintAndShade
'cell interior formating
'Set FCCIn = Xarr.FormatConditions(II).Interior.PatternColorIndex
FCC = Xarr(I, J).FormatConditions(II).Interior.Color
FCT = Xarr(I, J).FormatConditions(II).Interior.TintAndShade
'SET PROPERTY to NEW CELL
Yarr(I, J).Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:= _
FC.Operator, Formula1:=FC.Formula1
'Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
'cell font formatting
Selection.FormatConditions(II).Font.Color = FCFontC
Selection.FormatConditions(II).Font.TintAndShade = FCFOntT
'cell interior formating
With Selection.FormatConditions(II).Interior
.PatternColorIndex = xlAutomatic
.Color = FCC
.TintAndShade = FCT
End With
Selection.FormatConditions(Selection.FormatConditions.Count).StopIfTrue = False
Next II
End If
Next J
Next I
结束子
我的问题是“我如何也可以获得条件格式字体的属性?