Добрый день. У меня есть макрос, который заменяет цвета условного формата - на реальные цвета. Надо выделить область ячеек и нажать на кнопку. Однако макрос - не работает. Дело в том, что условных цветов в некоторых ячейках - несколько, а макрос выбирает - не тот цвет, который стоит в ячейке сейчас, а другой УФ - и присваивает ему реальный цвет.
Как изменить этот макрос, чтобы он убирая УФ - присваивал реальные цвета тому УФ, которое действует в ячейках на текущий момент ?
Добрый день. У меня есть макрос, который заменяет цвета условного формата - на реальные цвета. Надо выделить область ячеек и нажать на кнопку. Однако макрос - не работает. Дело в том, что условных цветов в некоторых ячейках - несколько, а макрос выбирает - не тот цвет, который стоит в ячейке сейчас, а другой УФ - и присваивает ему реальный цвет.
Как изменить этот макрос, чтобы он убирая УФ - присваивал реальные цвета тому УФ, которое действует в ячейках на текущий момент ?RipVanWinkel
не все так просто, в коде много переделывать Set FC = cell.FormatConditions(1) заменится на with cell.DisplayFormat, а далее все переписать для копирования формата до cell.FormatConditions.Delete При этом хорошоб копировать не только фон, но и формат текста.
не все так просто, в коде много переделывать Set FC = cell.FormatConditions(1) заменится на with cell.DisplayFormat, а далее все переписать для копирования формата до cell.FormatConditions.Delete При этом хорошоб копировать не только фон, но и формат текста.bmv98rus
Замечательный Временно просто медведь , процентов на 20.
RAN, ну можно пойти по неправедному пути, вычислить условия, определить старшинство уф ... и взять формат нужного. Но это не так интересно. Да и в котов я верю :-)
RAN, ну можно пойти по неправедному пути, вычислить условия, определить старшинство уф ... и взять формат нужного. Но это не так интересно. Да и в котов я верю :-)bmv98rus
Замечательный Временно просто медведь , процентов на 20.
Сообщение отредактировал bmv98rus - Воскресенье, 06.05.2018, 08:31
Формат "Число", созданный УФ, не обрабатывается. [vba]
Код
'--------------------------------------------------------------------------------------- ' Procedure : Format_Display ' DateTime : 07.05.2018 ' Author : RAN (ran.xls@ya.ru) ' Purpose : Замена форматов Условного Форматирования на реальные '--------------------------------------------------------------------------------------- ' Sub Format_Display() Dim cell As Range, rRange As Range Dim dfBorders As Object, dfFont As Object, dfInterior As Object Dim i&
If TypeName(Selection) <> "Range" Then MsgBox "Выделенная область не является диапазоном ячеек", _ vbCritical, "Неверные данные": Exit Sub If MsgBox("Форматы не входящие в стандартные (гистограммы и значки), будут утеряны! Продолжить?", _ vbExclamation + vbYesNo) <> vbYes Then Exit Sub Set rRange = Intersect(Selection, Selection.Parent.UsedRange) Application.ScreenUpdating = False For Each cell In rRange If cell.FormatConditions.Count Then
'%%%%%%%%%%%%%%%%%...Borders...%%%%%%%%%%%%%%%%%%%% Set dfBorders = cell.DisplayFormat.Borders With cell.Borders For i = 1 To 4 .Item(i).LineStyle = dfBorders.Item(i).LineStyle .Item(i).ColorIndex = dfBorders.Item(i).ColorIndex Next End With '%%%%%%%%%%%%%%%%%...Borders...%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%...Font...%%%%%%%%%%%%%%%%%%%% Set dfFont = cell.DisplayFormat.Font With cell.Font .Color = dfFont.Color .Bold = dfFont.Bold .Italic = dfFont.Italic .Strikethrough = dfFont.Strikethrough .Underline = dfFont.Underline End With '%%%%%%%%%%%%%%%%%...Font...%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%...Interior...%%%%%%%%%%%%%%%%%%%% Set dfInterior = cell.DisplayFormat.Interior With cell.Interior If Not dfInterior.Gradient Is Nothing Then .Pattern = dfInterior.Pattern Do While .Gradient.ColorStops.Count < dfInterior.Gradient.ColorStops.Count .Gradient.ColorStops.Add (0) DoEvents Loop If .Pattern = 4001 Then .Gradient.RectangleLeft = dfInterior.Gradient.RectangleLeft .Gradient.RectangleRight = dfInterior.Gradient.RectangleRight .Gradient.RectangleTop = dfInterior.Gradient.RectangleTop .Gradient.RectangleBottom = dfInterior.Gradient.RectangleBottom Else .Gradient.Degree = dfInterior.Gradient.Degree End If For i = 1 To dfInterior.Gradient.ColorStops.Count .Gradient.ColorStops(i).Color = dfInterior.Gradient.ColorStops(i).Color .Gradient.ColorStops(i).Position = dfInterior.Gradient.ColorStops(i).Position If dfInterior.Gradient.ColorStops(i).ThemeColor Then _ .Gradient.ColorStops(i).ThemeColor = dfInterior.Gradient.ColorStops(i).ThemeColor .Gradient.ColorStops(i).TintAndShade = dfInterior.Gradient.ColorStops(i).TintAndShade Next Else .Pattern = dfInterior.Pattern If .Pattern <> xlPatternNone Then .Color = dfInterior.Color .PatternColor = dfInterior.PatternColor End If End If End With '%%%%%%%%%%%%%%%%%...Interior...%%%%%%%%%%%%%%%%%%%% End If Next rRange.FormatConditions.Delete Application.ScreenUpdating = True
End Sub
[/vba]
Формат "Число", созданный УФ, не обрабатывается. [vba]
Код
'--------------------------------------------------------------------------------------- ' Procedure : Format_Display ' DateTime : 07.05.2018 ' Author : RAN (ran.xls@ya.ru) ' Purpose : Замена форматов Условного Форматирования на реальные '--------------------------------------------------------------------------------------- ' Sub Format_Display() Dim cell As Range, rRange As Range Dim dfBorders As Object, dfFont As Object, dfInterior As Object Dim i&
If TypeName(Selection) <> "Range" Then MsgBox "Выделенная область не является диапазоном ячеек", _ vbCritical, "Неверные данные": Exit Sub If MsgBox("Форматы не входящие в стандартные (гистограммы и значки), будут утеряны! Продолжить?", _ vbExclamation + vbYesNo) <> vbYes Then Exit Sub Set rRange = Intersect(Selection, Selection.Parent.UsedRange) Application.ScreenUpdating = False For Each cell In rRange If cell.FormatConditions.Count Then
'%%%%%%%%%%%%%%%%%...Borders...%%%%%%%%%%%%%%%%%%%% Set dfBorders = cell.DisplayFormat.Borders With cell.Borders For i = 1 To 4 .Item(i).LineStyle = dfBorders.Item(i).LineStyle .Item(i).ColorIndex = dfBorders.Item(i).ColorIndex Next End With '%%%%%%%%%%%%%%%%%...Borders...%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%...Font...%%%%%%%%%%%%%%%%%%%% Set dfFont = cell.DisplayFormat.Font With cell.Font .Color = dfFont.Color .Bold = dfFont.Bold .Italic = dfFont.Italic .Strikethrough = dfFont.Strikethrough .Underline = dfFont.Underline End With '%%%%%%%%%%%%%%%%%...Font...%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%...Interior...%%%%%%%%%%%%%%%%%%%% Set dfInterior = cell.DisplayFormat.Interior With cell.Interior If Not dfInterior.Gradient Is Nothing Then .Pattern = dfInterior.Pattern Do While .Gradient.ColorStops.Count < dfInterior.Gradient.ColorStops.Count .Gradient.ColorStops.Add (0) DoEvents Loop If .Pattern = 4001 Then .Gradient.RectangleLeft = dfInterior.Gradient.RectangleLeft .Gradient.RectangleRight = dfInterior.Gradient.RectangleRight .Gradient.RectangleTop = dfInterior.Gradient.RectangleTop .Gradient.RectangleBottom = dfInterior.Gradient.RectangleBottom Else .Gradient.Degree = dfInterior.Gradient.Degree End If For i = 1 To dfInterior.Gradient.ColorStops.Count .Gradient.ColorStops(i).Color = dfInterior.Gradient.ColorStops(i).Color .Gradient.ColorStops(i).Position = dfInterior.Gradient.ColorStops(i).Position If dfInterior.Gradient.ColorStops(i).ThemeColor Then _ .Gradient.ColorStops(i).ThemeColor = dfInterior.Gradient.ColorStops(i).ThemeColor .Gradient.ColorStops(i).TintAndShade = dfInterior.Gradient.ColorStops(i).TintAndShade Next Else .Pattern = dfInterior.Pattern If .Pattern <> xlPatternNone Then .Color = dfInterior.Color .PatternColor = dfInterior.PatternColor End If End If End With '%%%%%%%%%%%%%%%%%...Interior...%%%%%%%%%%%%%%%%%%%% End If Next rRange.FormatConditions.Delete Application.ScreenUpdating = True