B
bstobart
I'm trying to copy a large number of conditional formats from one set of
cells to another. I don't want to explicitly define the formatting in VBA,
but rather take it from an existing set of cells. Is there a way to do this
without parsing out all the various components of a given conditional format?
I tried the following, which failed miserably:
Dim intFormCondNum As Integer
' Loop over a set of Source/Destination cell pairs
With SourceCell
..Worksheet.Unprotect
DestCell.Worksheet.Unprotect
' ******** This part doesn't work**********
If DestCell.FormatConditions.Count > 0 Then
For intFormCondNum = 1 To DestCell.FormatConditions.Count
.FormatConditions(intFormCondNum) = _
DestCell.FormatConditions(intFormCondNum)
Next
End If
'***********************************
.Copy ' Copy formatted contents of SourceCell to the Clipboard
' Paste formatted contents of Clipboard to the DestCell
DestCell.PasteSpecial (xlPasteAllExceptBorders)
.Worksheet.Protect ' Protect the Source Cell worksheet
DestCell.Worksheet.Protect ' Protect the Destination Cell worksheet
End With ' SourceCell
As background, it may help to know that I'm copying source cells that have
rich text formatting, that I don't want to lose. Most of the formatting of
the end result should come from teh destination cell, but the text formatting
needs to come from the source. I've only just noticed that I've been
overwriting the destinations conditional formatting.
cells to another. I don't want to explicitly define the formatting in VBA,
but rather take it from an existing set of cells. Is there a way to do this
without parsing out all the various components of a given conditional format?
I tried the following, which failed miserably:
Dim intFormCondNum As Integer
' Loop over a set of Source/Destination cell pairs
With SourceCell
..Worksheet.Unprotect
DestCell.Worksheet.Unprotect
' ******** This part doesn't work**********
If DestCell.FormatConditions.Count > 0 Then
For intFormCondNum = 1 To DestCell.FormatConditions.Count
.FormatConditions(intFormCondNum) = _
DestCell.FormatConditions(intFormCondNum)
Next
End If
'***********************************
.Copy ' Copy formatted contents of SourceCell to the Clipboard
' Paste formatted contents of Clipboard to the DestCell
DestCell.PasteSpecial (xlPasteAllExceptBorders)
.Worksheet.Protect ' Protect the Source Cell worksheet
DestCell.Worksheet.Protect ' Protect the Destination Cell worksheet
End With ' SourceCell
As background, it may help to know that I'm copying source cells that have
rich text formatting, that I don't want to lose. Most of the formatting of
the end result should come from teh destination cell, but the text formatting
needs to come from the source. I've only just noticed that I've been
overwriting the destinations conditional formatting.