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

标签 excel vba

我在名为 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/

相关文章:

excel - 引用 If 语句的 'onclick' 事件 - IE 自动化

excel - 如何在没有VBA或宏的情况下在Excel中循环?

performance - VBA代码运行两个循环非常慢

vba - 在 excel vba 上处理错误

excel - 删除选定的行

excel - 如何通过vba找出excel中整行是否为空白

python Pandas : manually write to the same Excel after exporting a dataframe

excel - SUMIF 公式中 AND 逻辑运算符的使用

vba - 如何根据文本框值过滤列表框值

vba - Excel VBA : selected cells loop