У меня есть длинный макрос VBA, подобный этому:
Private Sub ApplyCondFormRun(CellFormat As Range, ValidFormula As String, TargetRange As Range, StopIfTrue As Boolean, Strict As Boolean)
'For this to work, cell addresses in validation formula must point to the first row
'of target cell
Dim ArrFormat(1 To 9) As Variant
Dim i As Long
'Application.ScreenUpdating = False
'attributes to be copied to destination cells
With CellFormat
ArrFormat(1) = .Font.Color 'Number
ArrFormat(2) = .Font.Size 'Number
ArrFormat(3) = .Font.Bold 'Boolean
ArrFormat(4) = .Font.Italic 'Boolean
ArrFormat(5) = .Font.Underline 'No: -4142, Single: 2, Double: -4119, Single Accounting: 4, Double Accounting: 5
If .Interior.ColorIndex = -4142 Then 'If cell is No fill then do nothing
ArrFormat(6) = .Interior.ColorIndex 'Number
Else
ArrFormat(6) = .Interior.Color
End If
ArrFormat(7) = .Borders(xlLeft).Color 'Number
ArrFormat(8) = .Borders(xlLeft).LineStyle 'Use only the left border style of the source cell & apply to whole destination cell
End With
ArrFormat(9) = StopIfTrue 'Boolean
TargetRange.FormatConditions.Add Type:=xlExpression, Formula1:=ValidFormula 'Add new cond formating
TargetRange.FormatConditions(TargetRange.FormatConditions.Count).SetFirstPriority
With TargetRange.FormatConditions(1)
.Font.Color = ArrFormat(1)
.Font.Size = ArrFormat(2)
....
Код останавливается на строке .Font.Size = ArrFormat(2)
с ошибкой "невозможно установить свойство размера класса шрифта". Я исследовал много мест, в том числе здесь , но мой лист вообще не защищен.
К вашему сведению, диапазон CellFormat - это первый столбец в выбранном диапазоне на фотографии выше. Я буду применять форматы этих ячеек к условным форматам ячеек назначения (3-й столбец).
Кроме того, строка над ней, .Font.Color = ArrFormat(1)
, работает без проблем.
Здесь скриншот ошибки. Как видите, размер шрифта 11.
Может кто-нибудь помочь?