例如:

rngTo.Value = rngFrom.Value2 'Works
rngTo.NumberFormat = rngFrom.NumberFormat 'Works
rngTo.Cells.Interior.ColorIndex = rngFrom.Cells.Interior.ColorIndex 'Doesn't work
rngToPublish.Copy: rNG.PasteSpecial xlPasteFormats ' Does work


有什么方法可以在不使用PasteSpecial的情况下获得所需的效果?

最佳答案

在上面的注释中,您只想复制填充色,请看以下示例:

Sub CopyFillColour()

    Dim rCopy As Range, rPaste As Range
    Dim lRow As Long, lCol As Long

    Set rCopy = Range("A1:B4")
    Set rPaste = Range("C1:D4") '// Can be smaller than the copy range ie C1:C4

    For lRow = 1 To rPaste.Rows.Count
        For lCol = 1 To rPaste.Columns.Count
            rPaste(lRow, lCol).Interior.Color = rCopy(lRow, lCol).Interior.Color
            rPaste(lRow, lCol).Interior.Pattern = rCopy(lRow, lCol).Interior.Pattern
            rPaste(lRow, lCol).Interior.PatternColorIndex = rCopy(lRow, lCol).Interior.PatternColorIndex
        Next lCol
    Next lRow

End Sub


我讨厌循环,这可能是您需要循环的情况。

09-16 04:15