Copy everything in a worksheet vba

谁说胖子不能爱 提交于 2020-01-04 06:01:12

问题


' Copy
wb.Sheets(wsSource.Name).Range("A1:W79").Copy
' Paste Special
wbTarget.Sheets("Sheet1").Range("A1:W79").PasteSpecial xlValues
wbTarget.Sheets("Sheet1").Range("A1:W79").PasteSpecial xlFormats

This code allows me to copy everything in a range of A1:W79. How can I modify this Range so that it selects everything that contains value in a worksheet. For example, worksheet might contain values from C7:G20 etc.


回答1:


I'd go like follows:

With wb.Sheets(wsSource.Name).UsedRange
    .Copy
    With wbTarget.Sheets("Sheet1").Range(.Address)
        .PasteSpecial xlValues
        .PasteSpecial xlFormats
    End With
End With


来源:https://stackoverflow.com/questions/43114161/copy-everything-in-a-worksheet-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!