Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Excel > Excel Programming

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 11-08-2015, 09:40 PM
Snaybot Snaybot is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Sep 2015
Posts: 22
Snaybot is on a distinguished road
Default VBA merging cells and counting Merged rows

I have a series of varying merged cells only in column A, such as a merged cell of 8 rows and then next merge cells is 4 cells and the next is 7 cells and so on and so on...




I Would like to figure out How to create a macro that instead of the 8 row merged cell it goes to 7 cells

So I would like the existing merged cells row count to go down by 1

so for 8 row merged cell it would go to a 7 row merged cell

so for 5 row merged cell it would go to a 4 row merged cell

so for 20 row merged cell it would go to a 19 row merged cell
Reply With Quote
  #2  
Old 11-09-2015, 03:02 AM
Debaser's Avatar
Debaser Debaser is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Posts: 165
Debaser is on a distinguished road
Default

You could do this:

Code:
Sub resizeMerge()

    Dim lRow                  As Long
    Dim lCount                As Long
    Dim lLastRow              As Long

    lRow = 1

    ' change to your last row
    lLastRow = 25

    Do While lRow <= lLastRow
        With Cells(lRow, "A")
            If .MergeCells Then
                lCount = .MergeArea.Cells.Count
                .UnMerge
                If lCount > 2 Then .Resize(lCount - 1).Merge
            End If
        End With
        lRow = lRow + lCount
    Loop
End Sub
Reply With Quote
  #3  
Old 11-09-2015, 03:56 AM
Snaybot Snaybot is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Sep 2015
Posts: 22
Snaybot is on a distinguished road
Default

Thank you!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
counting cells to the right of criteria Taras49 Excel 5 11-05-2015 11:52 AM
Table will not allow sorting because "cells are merged". I can't find the merged cells. wendyloooo Word Tables 1 05-26-2015 01:19 PM
Merging Rows - HELP please! MessyJessy Excel 7 01-14-2015 01:38 AM
Counting Color in Cells Alaska1 Excel 7 07-28-2013 04:36 PM
merging rows and creating sub-rows gib65 Excel 2 12-09-2011 02:09 PM


All times are GMT -7. The time now is 10:17 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft