Count the number of merged cells

dsheridan35

New Member
Joined
Jun 7, 2016
Messages
2
So I am trying to create a macro to count the number of tasks that are completed in a schedule. The schedule is for each day and it runs from 1am to the following midnight. The tasks are inputted as merged cells between the time the task is to take place. So what I need the macro to do is count a range of merged cells as 1 task and not the number of individual cells used to make up the merged cell.

Can anyone help me out?

Thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Possibly the Range.MergeArea property could assist.

Iterate each rngCell of the desired range
Store rngCell.MergeArea.Address and as a ScriptingDictionary Key and the rngCell.MergeArea.Cells.Count as the associated Item
Count the number of SD Keys that have an item <> 1
 
Upvote 0
Hi give this a try.
Code:
Sub CountMergedRange()


Dim Rng As Range
Dim WorkRng As Range
Dim OutRng As Range


On Error Resume Next
Set WorkRng = ActiveSheet.UsedRange
For Each Rng In WorkRng
    If Rng.MergeCells Then
        If OutRng Is Nothing Then
            Set OutRng = Rng
        Else
            Set OutRng = Union(OutRng, Rng)
        End If
    End If
Next
If Not OutRng Is Nothing Then
    OutRng.Select
    MsgBox "There are " & Selection.Areas.Count & " merged range."
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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