vba excel如何粘贴没有字体/颜色/ bg颜色格式的值

Kir*_*ngs 3 excel vba paste

我有一个宏来复制一系列工作表中的每个工作表的摘要行.摘要行使用字体/字体颜色/ bg颜色进行特殊格式化,但是当粘贴到"sumamry工作表"时,它只需粘贴值而不进行格式化.

For LoopIndex = StartIndex To EndIndex
    ' start in a task sheet
    Sheets(LoopIndex).Select
    CopiedCells = ActiveSheet.Range("A156:L156").Copy

    ' now move to Summary sheet
    Sheets("Summary Sheet").Select
    ActiveSheet.Range("A8").Select
    ActiveCell.EntireRow.Insert

    ActiveCell.PasteSpecial Paste:=xlPasteValues
    ' tried variations of: ActiveCell.PasteSpecial paste:=xlValues, operation:=xlPasteSpecialOperationNone

    Application.CutCopyMode = False ' clears clipboard
Next LoopIndex
Run Code Online (Sandbox Code Playgroud)

我所做的所有研究都说过PastSpecial,xlValues,xlPasteValues应该可以工作,但没有什么可以去除格式化,不知道我在这里做错了什么.它会粘贴值而不是引用的值,因此这很好.我有一个宏来重置循环中的格式,但我想提高效率.我正在使用Excel 2007.

Chr*_*yne 6

那太奇怪了!

原因是你正在复制,插入然后粘贴.尝试插入,复制,然后粘贴:

'we must commence on the Summary Sheet
Sheets("Summary Sheet").Select
For LoopIndex = StartIndex To EndIndex

    ' insert the row before we start
    ActiveSheet.Range("A8").Select
    ActiveCell.EntireRow.Insert

    ' select the task sheet
    Sheets(LoopIndex).Select
    CopiedCells = ActiveSheet.Range("A156:L156").Copy

    ' now move to Summary sheet
    Sheets("Summary Sheet").Select

    ActiveCell.PasteSpecial Paste:=xlPasteValues
    ' tried variations of: ActiveCell.PasteSpecial paste:=xlValues, operation:=xlPasteSpecialOperationNone

    Application.CutCopyMode = False ' clears clipboard
Next LoopIndex
Run Code Online (Sandbox Code Playgroud)

对于它的价值,我在使用复制和粘贴方面遇到了问题.这意味着当您的宏运行时,您无法做其他事情.

由于它是固定范围,我建议:

For LoopIndex = StartIndex To EndIndex
    Sheets("Summary Sheet").Range("A8").EntireRow.Insert
    For i = 1 To 12
        Sheets("Summary Sheet").Cells(8, i) = Sheets(LoopIndex).Cells(156, i)
    Next
Next
Run Code Online (Sandbox Code Playgroud)