0

I perform this code 11 times on my macro

Windows("LOFORM.xls").Activate
Sheets("Becke").Select
Range("A6:J25").Select
Selection.Copy
Windows("Comp Reform LO.xls").Activate
Sheets("Becke").Select
Range("A6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

for all different sheets. Instead of having this entire code 11 separate time with different sheet names can I condense it?

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

4

This is much mroe compact, but also as it avoids all selects, activates and working with the clip board it will also be much faster.

Windows("Comp Reform LO.xls").Sheets("Becke").Range("A6:J25") = _
Windows("LOFORM.xls").Sheets("Becke").Range("A6:J25")

If you have this code 11 times through out your code you should turn it into its own sub, and simply call it as CopyValues() or something.

Or if the code 11 times is similar but different locations you could also pass in the Workbook and worksheet params:

    Sub SampleCopyValues(DestinationWorkSheet As Worksheet)
        DestinationWorkSheet.Range("A6:J25") = _
        Windows("LOFORM.xls").Sheets("Becke").Range("A6:J25")
    End Sub

Then you could call it as SampleCopyValues(Windows("Comp Reform LO.xls").Sheets("Becke"))

user2140261
  • 7,855
  • 7
  • 32
  • 45