ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can I use loops to enhance this code? (https://www.excelbanter.com/excel-programming/444907-can-i-use-loops-enhance-code.html)

Max[_8_]

Can I use loops to enhance this code?
 
Can I use loops to enhance this code?
Sheet24.Cells(5, 2).Copy Destination:=Sheet5.Cells(10, 3)
Sheet24.Cells(5, 3).Copy Destination:=Sheet5.Cells(10, 4)
Sheet24.Cells(5, 4).Copy Destination:=Sheet5.Cells(11, 3)
Sheet24.Cells(5, 5).Copy Destination:=Sheet5.Cells(11, 4)
Sheet24.Cells(5, 6).Copy Destination:=Sheet5.Cells(12, 3)
Sheet24.Cells(5, 7).Copy Destination:=Sheet5.Cells(12, 4)
Sheet24.Cells(5, 8).Copy Destination:=Sheet5.Cells(13, 3)
Sheet24.Cells(5, 9).Copy Destination:=Sheet5.Cells(13, 4)
Sheet24.Cells(5, 10).Copy Destination:=Sheet5.Cells(14, 3)
Sheet24.Cells(5, 11).Copy Destination:=Sheet5.Cells(14, 4)
Sheet24.Cells(5, 12).Copy Destination:=Sheet5.Cells(15, 3)
Sheet24.Cells(5, 13).Copy Destination:=Sheet5.Cells(15, 4)
Sheet24.Cells(5, 14).Copy Destination:=Sheet5.Cells(16, 3)
Sheet24.Cells(5, 15).Copy Destination:=Sheet5.Cells(16, 4)

Javed

Can I use loops to enhance this code?
 
Sub LoopEffect()

Dim Sheet24 As Worksheet, Sheet5 As Worksheet
Dim i As Long, j As Long

Set Sheet24 = Worksheets(2)
Set Sheet5 = Worksheets(3)

For i = 2 To 15
j = i Mod 2
Sheet5.Cells((9 + (i - j) / 2), j + 3) = Sheet24.Cells(5,
i).Value
Next i

End Sub

Pls check.

Max[_8_]

Can I use loops to enhance this code?
 
That worked perfectly - thank you very much!!


All times are GMT +1. The time now is 01:50 AM.

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