1

我在名为的工作表中有一个单元格,A我必须将其复制然后将其粘贴到Range(Cells(23, 60), cells(23, 78))名为B.

我应该怎么做 ?

我考虑过使用动态单元格引用,例如:copyrange = Range(Cells(696, 60), Cells(696, 60))

4

4 回答 4

3

这是你正在尝试的吗?

Sub Sample()
    Dim wsFrom As Worksheet, wsTo As Worksheet
    Dim CopyFrom As Range, CopyTo As Range
    Dim r1 As Long, r2 As Long, r3 As Long, r4 As Long
    Dim c1 As Long, c2 As Long, c3 As Long, c4 As Long

    Set wsFrom = ThisWorkbook.Sheets("A")
    Set wsTo = ThisWorkbook.Sheets("B")

    r1 = 696: c1 = 60
    r2 = 696: c2 = 60
    r3 = 23: c3 = 60
    r4 = 23: c4 = 78

    With wsFrom
        Set CopyFrom = .Range(.Cells(r1, c1), .Cells(r2, c2))
    End With

    With wsTo
        Set CopyTo = .Range(.Cells(r3, c3), .Cells(r4, c4))
    End With

    CopyFrom.Copy CopyTo
End Sub
于 2013-06-17T14:25:21.270 回答
0

你并没有真正给我们很多东西,所以我会发布一种方式,看看它是否能让你继续前进:

Sub test()
Dim columnReferenceSource     As Long
Dim rowReferenceSource        As Long
Dim columnReferenceDest       As Long
Dim rowReferenceDest          As Long
Dim r                         As Range

rowReferenceSource = 696
columnReferenceSource = 60

rowReferenceDest = 23
columnReferenceDest = 60

Set r = Range(Sheets("A").Cells(rowReferenceSource, columnReferenceSource), Sheets("A").Cells(rowReferenceSource, columnReferenceSource + 18))

r.Copy Destination:=Sheets("B").Cells(rowReferenceDest, columnReferenceDest)

End Sub

显然,您必须根据您的情况设置行号和列号。如果您可以提供有关您要做什么的更多详细信息,我相信我们可以给出更完整的答案。例如,您如何确定源和目标范围?

于 2013-06-17T14:15:33.927 回答
0

考虑:

Sub dural()
Dim r As Range
With Sheets("Sheet2")
    Sheets("Sheet1").Cells(696, 60).Copy Sheets("Sheet2").Range(.Cells(23, 60), .Cells(23, 78))
End With
End Sub
于 2013-06-17T14:25:22.930 回答
0

不要忘记之前的工作表名称cells()

sub CopyA_PasteB()

dim wb as Workbook
dim wsA as worksheet
dim wsB as worksheet

set wb = Workbooks("WORKBOOK NAME")
set shA = wb.Worksheets("A")
set shB = wb.Worksheets("B")

shA.Range(shA.Cells(696, 60), shA.Cells(696, 60)).Copy
shB.Range("A1").Paste     'replace with your destination

End sub
于 2018-10-23T17:30:37.880 回答