Win XP, Office 2003
I have a worksheet containing +- 900 rows.
How do I merge cells in cols A to F ONLY in rows 1, 6, 11 and so on.
In col A there are text values rows 1, 6, 11 and so on, the other rows, in
col A, are blank
All other rows to be left as they were
Paul Morgan - 04 Mar 2007 05:06 GMT
Why would you want to do that?
--
Paul Morga
Posted from - http://www.officehelp.i
Dave Peterson - 04 Mar 2007 14:02 GMT
Merged cells can cause lots of problems later on--sorting, filtering,
copy|pasting...
You may want to consider center across selection instead.
But if you really need them, you could use a macro:
Option Explicit
Sub testme()
Dim iRow As Long
Dim wks As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim HowManyCols As Long
Set wks = ActiveSheet
With wks
HowManyCols = 6 'A:F is 6 columns
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'or 900
Application.DisplayAlerts = False
For iRow = 1 To LastRow Step 5
.Cells(iRow, "A").Resize(1, HowManyCols).Merge
Next iRow
Application.DisplayAlerts = True
End With
End Sub
If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
> Win XP, Office 2003
> I have a worksheet containing +- 900 rows.
> How do I merge cells in cols A to F ONLY in rows 1, 6, 11 and so on.
> In col A there are text values rows 1, 6, 11 and so on, the other rows, in
> col A, are blank
> All other rows to be left as they were

Signature
Dave Peterson
Dave Peterson - 04 Mar 2007 14:06 GMT
I see in your next message that you're deleting rows with empty cells in a
certain column.
If that leaves nothing but the rows that should be merged, you can merge them in
one step:
Option Explicit
Sub testme2()
Dim wks As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim HowManyCols As Long
Set wks = ActiveSheet
With wks
HowManyCols = 6 'A:F is 6 columns
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'or 900
Application.DisplayAlerts = False
.Range(.Cells(FirstRow, "A"), .Cells(LastRow, "A")) _
.Resize(, HowManyCols).Merge across:=True
Application.DisplayAlerts = True
End With
End Sub
> Win XP, Office 2003
> I have a worksheet containing +- 900 rows.
> How do I merge cells in cols A to F ONLY in rows 1, 6, 11 and so on.
> In col A there are text values rows 1, 6, 11 and so on, the other rows, in
> col A, are blank
> All other rows to be left as they were

Signature
Dave Peterson
Paul Morgan - 04 Mar 2007 14:28 GMT
try this out
Code
-------------------
Sub Button1_Click()
Application.DisplayAlerts = False
Range("A1").Select
Do Until ActiveCell = ""
ActiveCell.Range("A1:F1").Merge
ActiveCell.Offset(5, 0).Select
Loop
[A1].Select
End Su
-------------------
--
Paul Morga
Posted from - http://www.officehelp.i