Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / March 2007

Tip: Looking for answers? Try searching our database.

Merge cells selectively?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SouthAfricanStan - 04 Mar 2007 04:40 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.