如何复制范围中的两个非相邻列

时间:2018-05-24 17:56:49

标签: excel-vba vba excel

我需要复制D列和D列。 H并粘贴到表格中。 这就是我到目前为止所拥有的。 我尝试了几个不同的修改搜索这个网站没有运气。 感谢

Sub Zulily_DS()
On Error Resume Next

Dim lastrowB As Long
Dim lastrowB1 As Long
Dim myLastCell As Range

Application.ScreenUpdating = True

lastrowB = Sheets("Source").Cells(Rows.Count, "B").End(xlUp).Row + 1
lastrowB1 = Sheets("Source").Cells(Rows.Count, "B").End(xlUp).Row

Sheets("Source").Select
With Sheets("Zulily_DS")

If Sheets("Source").Range("C2").Value = vbNullString Then
    .Range("D2:H2", .Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Copy _
                                                                            Sheets("Source").Cells(lastrowB1, 2)

ElseIf Sheets("Source").Range("C2").Value > "0" Then
    .Range("D2:H2", .Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Copy _
                                                                            Sheets("Source").Cells(lastrowB, 2)
End If
End With

Application.ScreenUpdating = False
End Sub

1 个答案:

答案 0 :(得分:-2)

如果不是将您的范围分开,而不是:

DockContent

更改为:

Range("A1:A2","D1:D2")

请注意,引号不会将范围彼此分开。他们会像你期望的那样粘贴表格格式:

而不是:

Range("A1:A2,D1:D2")

使用此:

Range("A1:A2","D1:D2").Copy Range("B6:C7")

第一种是复制不同的范围,而第二种是组合范围。

相关问题