2
' 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.

0m3r
  • 11,696
  • 15
  • 30
  • 65
Ninja Dude
  • 1,236
  • 3
  • 24
  • 46

1 Answers1

4

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
user3598756
  • 27,674
  • 4
  • 17
  • 26