Sub CopyOnlyFormatCondionColorSAS()
Dim c As Range
Dim x As Long
On Error Resume Next
For Each c In ActiveSheet.UsedRange. _
SpecialCells(xlCellTypeAllFormatConditions)
x = c.FormatConditions(1).Interior.ColorIndex
c.FormatConditions.Delete
c.Interior.ColorIndex = x
Next c
End Sub
Option Explicit
Sub convertSheet()
Dim sheetToConvert As Worksheet
Dim rngConditionalFormatted As Range
Dim uiRange As Range
On Error Resume Next
Set uiRange = Application.InputBox("Select a Worksheet to convert", Type:=8)
On Error GoTo 0
If uiRange Is Nothing Then Exit Sub
If MsgBox("Convert " & Trim(Left(Application.Substitute(uiRange.Address(, , , True), "$", String(255, " ")), 255)) & " ?", _
vbYesNo) = vbNo Then Exit Sub
Set sheetToConvert = uiRange.Parent
'Set sheetToConvert = ThisWorkbook.Sheets("Sheet1"): Rem adjust
On Error Resume Next
Set rngConditionalFormatted = sheetToConvert.Cells.SpecialCells(xlCellTypeAllFormatConditions)
On Error GoTo 0
If Not rngConditionalFormatted Is Nothing Then
Call ConvertCFtoBaseFormat(rngConditionalFormatted)
Else
MsgBox "no cf"
End If
End Sub
Sub ConvertCFtoBaseFormat(rangeToConvert As Range)
Dim oneCell As Range
Application.ScreenUpdating = False
For Each oneCell In rangeToConvert
If CFormatMet(oneCell) <> 0 Then
Call CopyCFto(oneCell, CFormatMet(oneCell))
End If
oneCell.FormatConditions.Delete
Next oneCell
Application.ScreenUpdating = True
End Sub
Sub CopyCFto(sourceCell As Range, CFConditionMet As Long, Optional destinationCell As Range)
Rem Set destination cell base formatting = source cell conditional format #
If destinationCell Is Nothing Then Set destinationCell = sourceCell.Cells(1, 1)
Dim anEdge As Variant
With sourceCell.Cells(1, 1).FormatConditions(CFConditionMet)
With .Font
If Not IsNull(.Bold) Then destinationCell.Font.Bold = .Bold
If Not IsNull(.Italic) Then destinationCell.Font.Italic = .Italic
If Not IsNull(.Underline) Then destinationCell.Font.Underline = .Underline
If Not IsNull(.Strikethrough) Then destinationCell.Font.Strikethrough = .Strikethrough
If Not IsNull(.ColorIndex) Then destinationCell.Font.ColorIndex = .ColorIndex
End With
On Error Resume Next
For Each anEdge In Array(xlLeft, xlRight, xlTop, xlBottom)
With .Borders(anEdge)
If Not IsNull(.LineStyle) Then destinationCell.Borders(anEdge).LineStyle = .LineStyle
If Not IsNull(.Weight) Then destinationCell.Borders(anEdge).Weight = .Weight
If Not IsNull(.ColorIndex) Then destinationCell.Borders(anEdge).ColorIndex = .ColorIndex
End With
Next anEdge
On Error GoTo 0
With .Interior
If Not IsNull(.PatternColorIndex) Then _
destinationCell.Interior.PatternColorIndex = .PatternColorIndex
If Not IsNull(.Pattern) Then destinationCell.Interior.Pattern = .Pattern
If Not IsNull(.ColorIndex) Then destinationCell.Interior.ColorIndex = .ColorIndex
End With
End With
End Sub
Function CFormatMet(oneCell As Range) As Long
Rem which of the three conditional formatting conditions is met
Rem given a cell, returns the number of the conditional format condtion that is met
Rem if CF not engaged, returns 0
Dim testFormula As String, tempFormula As String
Dim i As Long
With oneCell
For i = 1 To .FormatConditions.Count
testFormula = .Value
If testFormula = vbNullString Then testFormula = 0
With .FormatConditions(i)
If .Type = xlCellValue Then
Select Case .Operator
Case xlBetween
testFormula = "AND(" & .Formula1 & "<=" & testFormula & "," & testFormula & "<=" & .Formula2 & ")"
Case xlNotBetween
testFormula = "NOT(AND(" & .Formula1 & "<=" & testFormula & "," & testFormula & "<=" & .Formula2 & "))"
Case xlEqual
testFormula = testFormula & "=" & .Formula1
Case xlGreater
testFormula = testFormula & ">" & .Formula1
Case xlGreaterEqual
testFormula = testFormula & ">=" & .Formula1
Case xlLess
testFormula = testFormula & "<" & .Formula1
Case xlLessEqual
testFormula = testFormula & "<=" & .Formula1
Case xlNotEqual
testFormula = testFormula & "<>" & .Formula1
End Select
Else
tempFormula = Application.ConvertFormula(.Formula1, FromReferenceStyle:=xlA1, ToReferenceStyle:=xlR1C1)
testFormula = Application.ConvertFormula(tempFormula, FromReferenceStyle:=xlR1C1, ToReferenceStyle:=xlA1, _
ToAbsolute:=True, RelativeTo:=oneCell)
End If
End With
If Evaluate(testFormula) Then Exit For
Next i
End With
CFormatMet = i Mod (oneCell.FormatConditions.Count + 1)
End Function
Option Explicit
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 1/16/2010 by Mike Erickson
'
'
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _
Formula1:="5"
With Selection.FormatConditions(1).Borders(xlLeft)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = 3
End With
With Selection.FormatConditions(1).Borders(xlRight)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = 3
End With
With Selection.FormatConditions(1).Borders(xlTop)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = 3
End With
With Selection.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = 3
End With
Selection.FormatConditions(1).Interior.ColorIndex = 23
End Sub
Sub makeCFDialog()
Application.Dialogs(xlDialogConditionalFormatting).Show
End Sub
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 1/16/2010 by Mike Erickson
'
'
Application.Run "CF.xls!makeCFDialog"
End Sub
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 1/16/2010 by Mike Erickson
'
'
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _
Formula1:="5"
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = True
.Underline = xlUnderlineStyleSingle
.Strikethrough = True
.ColorIndex = 9
End With
With Selection.FormatConditions(1).Borders(xlLeft)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = 3
End With
With Selection.FormatConditions(1).Borders(xlRight)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = 3
End With
With Selection.FormatConditions(1).Borders(xlTop)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = 3
End With
With Selection.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = 3
End With
With Selection.FormatConditions(1).Interior
.ColorIndex = 46
.PatternColorIndex = 33
.Pattern = xlDown
End With
End Sub
Sub Macro4()
'
' Macro4 Macro
' Macro recorded 1/16/2010 by Mike Erickson
'
'
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub