gpt4 book ai didi

excel - vba范围(单元格(),单元格())复制过去到另一个工作表而不激活另一个工作表

转载 作者:行者123 更新时间:2023-12-04 22:07:43 25 4
gpt4 key购买 nike

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

我应该怎么做 ?

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

最佳答案

这是你正在尝试的吗?

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

关于excel - vba范围(单元格(),单元格())复制过去到另一个工作表而不激活另一个工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17149562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com