我在名为A
的工作表中有一个单元格,我必须将其复制,然后将其粘贴到名为Range(Cells(23, 60), cells(23, 78))
的工作表的B
。
我该怎么办?
我考虑使用动态单元格引用,例如:copyrange = Range(Cells(696, 60), Cells(696, 60))
。
答案 0 :(得分:4)
这是你在尝试的吗?
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
答案 1 :(得分: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
显然,您必须为您的情况设置行号和列号。如果您可以提供有关您尝试做的更多详细信息,我相信我们可以提供更完整的答案。例如,您如何确定源和目标范围?
答案 2 :(得分: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
答案 3 :(得分: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