for loops

MAMIBUSSOL

Board Regular
Joined
Jun 2, 2011
Messages
95
is it possible to re-code this into a for loop

Code:
    Range("A5:D5").MergeCells = True
    Range("A6:D6").MergeCells = True
    Range("A7:D7").MergeCells = True
    Range("A8:D8").MergeCells = True
    Range("A9:D9").MergeCells = True
    Range("A10:D10").MergeCells = True
    Range("A11:D11").MergeCells = True
    Range("A12:D12").MergeCells = True
    Range("A13:D13").MergeCells = True
    Range("A14:D14").MergeCells = True
    Range("A15:D15").MergeCells = True
    Range("A16:D16").MergeCells = True
    Range("A17:D17").MergeCells = True
    Range("A18:D18").MergeCells = True
    Range("A19:D19").MergeCells = True
    Range("A20:D20").MergeCells = True
    Range("A21:D21").MergeCells = True
    Range("A22:D22").MergeCells = True
    Range("A23:D23").MergeCells = True
    Range("A24:D24").MergeCells = True
    Range("A25:D25").MergeCells = True
    Range("A26:D26").MergeCells = True
    Range("A27:D27").MergeCells = True
    Range("A28:D28").MergeCells = True
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this untested

Dim i as integer

For i = 5 to 28

Range(Cells(i,1),cells(i,4)).MergeCells = True

Next i
 
Upvote 0
SURE,,,,,,,,,,,,

Code:
Sub Foo()
Dim i As Long
Application.DisplayAlerts = False
For i = 5 To 28
Range(Cells(i, 1), Cells(i, 4)).MergeCells = True
Next i
Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top