VBA to format merged cells?

MsDeth

New Member
Joined
May 8, 2004
Messages
41
Can't figure out the correct terminology for a macro to format the interior of merged cells in a selected range...something along these lines:

With Selection
If .MergeCells = True Then

With Selection.Interior
.ColorIndex = 19
.Pattern = xlSolid
.PatternColorIndex = 17
End With
End If
End With
'etc., etc.

I realize that this code won't work, but hope that it gives the gist of what I'm asking--any suggestions much appreciated!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
The code seems like working on my workbook... just make sure the selection contains only the merged cells, not additional cells... if it still doesnt work put a break point and make sure it is where it's breaking... as i told you it seems like working on mine.
 
Upvote 0
It worked for me:

Sub mergecheck()
If Range("A1").MergeCells Then
MsgBox "Cell is Merged"


With Range("A1").Interior
.ColorIndex = 19
.Pattern = xlSolid
.PatternColorIndex = 17
End With
Else
MsgBox "Cell is not Merged"
End If
End Sub
 
Upvote 0
How about this?

Code:
Sub test2()
Dim c As Range
For Each c In Selection
    If c.MergeCells Then c.Interior.ColorIndex = 19
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,310
Messages
6,124,187
Members
449,147
Latest member
sweetkt327

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