热线电话:13121318867

登录
2019-01-17 阅读量: 814
从工作表中选择单元格复制到另一个工作表

如何将sheet1中的多个单元格(逐个)复制到sheet2中的单个单元格。

每次单击按钮都会将sheet1的单个单元格复制到sheet2单元格“B4”

这是我的示例代码:


Dim lRow, RowIndex As Long
Dim src As Worksheet, dest As Worksheet

Dim rng As Range

Set src = ThisWorkbook.Worksheets("sheet1")
Set dest = ThisWorkbook.Worksheets("sheet2")
lRow = src.Range("D8").End(xlDown).Row
RowIndex = 1

For Each rng In src.Range("D8:D" & lRow)



src.Range(rng & RowIndex).Copy Destination:=dest.Range("B4")

Selection.Copy

RowIndex = RowIndex + 1

Next rng


Application.CutCopyMode = False

其实可以尝试以下解决方法

Sub CopyToSingleCell()
Dim lRow, RowIndex As Long
Dim src As Worksheet, dest As Worksheet
Dim rng As Range

Set src = ThisWorkbook.Worksheets("sheet1")
Set dest = ThisWorkbook.Worksheets("sheet2")
lRow = src.Range("D8").End(xlDown).Row

For Each rng In src.Range("D8:D" & lRow)
dest.Range("B4") = dest.Range("B4") & " " & rng.Value
Next rng

Set src = Nothing
Set dest = Nothing
End Sub
75.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子