将一系列数据作为图片复制/粘贴到左侧并复制相同的范围并粘贴到右侧的上一个粘贴

时间:2016-05-05 22:53:37

标签: excel-vba vba excel

我有一系列数据A1:M55经常变化,我想拍摄该范围的历史紫色拍摄照片,然后粘贴到工作表右侧的图片中。每次运行宏时,它会将图片粘贴一行粘贴最后粘贴的图片,在每个粘贴的事件之间留下一个空行。也希望在AA单元格中出现第一个粘贴:1。

以下版本是我尝试过的,但根据结果我使用了错误的方法。

Sub CopyHistory2()

Range("A1:M55").Select

Selection.Copy


ActiveSheet.Range(ActiveSheet.UsedRange.Columns.Count + 1).Select

Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

End Sub

1 个答案:

答案 0 :(得分:0)

能够结合多个问题的解决方案来获得我想要的输出。

Dim source As Worksheet
Dim destination As Worksheet
Dim emptyColumn As Long

Set source = Sheets("Sheet1")
Set destination = Sheets("Sheet1")

'find empty Column (actually cell in Row 1)'
emptyColumn = destination.Cells(1, destination.Columns.Count).End(xlToLeft).Column
If emptyColumn > 1 Then
emptyColumn = emptyColumn + 1
End If

source.Range("A1:M55").Copy

destination.Cells(1, emptyColumn).PasteSpecial xlPasteValuesAndNumberFormats
destination.Cells(1, emptyColumn).PasteSpecial xlPasteFormats
Application.CutCopyMode = False
相关问题