ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Simplify this code (https://www.excelbanter.com/excel-programming/352675-simplify-code.html)

scott

Simplify this code
 
How can I simplify this code to a more compressed format?

Sheets("WK1").Select
Range("B2:H8").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B63").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B12:H18").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B73").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B22:H28").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B83").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B32:H38").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B93").Select
Selection.PasteSpecial Paste:=xlPasteValues

Jim Thomlinson[_5_]

Simplify this code
 
This is a little shorter...

With Sheets("Web Sheet")
Sheets("WK1").Range("B2:H8").Copy
.Range("B63").PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Range("B12:H18").Copy
.Range("B73").PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Range("B22:H28").Copy
.Range("B83").PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Range("B32:H38").Copy
.Range("B93").PasteSpecial Paste:=xlPasteValues
End With

--
HTH...

Jim Thomlinson


"Scott" wrote:

How can I simplify this code to a more compressed format?

Sheets("WK1").Select
Range("B2:H8").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B63").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B12:H18").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B73").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B22:H28").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B83").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B32:H38").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B93").Select
Selection.PasteSpecial Paste:=xlPasteValues


JMB

Simplify this code
 
Since your Source and destination ranges are spaced the same and consistent
in the number of rows used, you could also use a loop:

Sub CopyData()
Dim i As Integer

With Sheets("Web Sheet")
For i = 0 To 30 Step 10
Sheets("WK1").Range("B" & 2 + i & ":H" & 8 + i).Copy
.Range("B" & 63 + i).PasteSpecial Paste:=xlPasteValues
Next i
End With
End Sub


"Scott" wrote:

How can I simplify this code to a more compressed format?

Sheets("WK1").Select
Range("B2:H8").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B63").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B12:H18").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B73").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B22:H28").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B83").Select
Selection.PasteSpecial Paste:=xlPasteValues

Sheets("WK1").Select
Range("B32:H38").Select
Selection.Copy
Sheets("Web Sheet").Select
Range("B93").Select
Selection.PasteSpecial Paste:=xlPasteValues



All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com