Help! with macro loop please, merge range loop


Posted by Ken on December 28, 2001 1:36 PM

Sub Macro2()
Range("F1:K1").Merge
Range("F2:K2").Merge
End Sub

I would like to merge F through K, row by row up to row 350, I don't know how to loop through each row.

Thank you
Ken

Posted by steve on December 28, 2001 2:23 PM


you might try:

dim count as integer
range("a1").select

count = 1
do while count < 350

Range("$f1:$k1").Select
<do whatever you are doing to your range here>
count = count + 1
loop

im kind of a noobie so im not sure if the dollar signs go in front of the static information (what doesnt change --- in your case the columns) or dynamic (what does change)

if that doesn't work you might try:

dim count as integer
range("a1").select

count = 1
do while count < 350

Range("f" & count:"k" & count).Select
<do whatever you are doing to your range here>
count = count + 1
loop

Posted by Gary Bailey on December 28, 2001 3:07 PM

In this case I don't think you need to loop through. Try

Range("f1:k350").Merge True

The merge method accepts an extra argument that makes the merging row by row rather than one enormous 350 row cell.

You might like to supress the warning message you get if the cells contain data using:

Application.DisplayAlerts = False
Range("f1:k300").Merge True
Application.DisplayAlerts = True

Gary



Posted by Ken on December 28, 2001 3:21 PM

Your awesome Gary, Thanks, Funny I called the macro Sub Merge