Problem with merged cells

mutrus

Board Regular
Joined
Sep 10, 2002
Messages
80
The display below has not quite come out properly but it should show all the days of the month. It is an activity planner. There are also lots more rows
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1(UsethespacebelowtoenterMonthlyTasks)
2
3
4
5TFSSMTWTFSSMTWTFSSMTWTFSSM
61234567891011121314151617181920212223242526
7HQStaff
8
9
10
11ProjectsStaff
Sheet1


There is a button on the menu that shows a user form from which a date is selected. The code then colours the selected column grey which signifies that this day is a Holiday.

My problem is how to skip over the rows that contain merged cells that cover the selected column. I already have code that can cope with merged cells that cover the entire row (example rows 7, 11 & 15) but not row 8 if I select column I for the holiday

So what I need is code to do this: If I want Friday 9th to be a holiday then all cells in range I5:I15 to be coloured grey except those cell that are merged

Hope this is not too confusing
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I'm interested in this too.
Testing already since this is published didn't find anything neigther that worked in one operation.
But this works.

Code:
Sub color()
For Each ccc In Range("I5:I15")
ccc.Select
If Selection.Column = Range("I15").Column Then ccc.Interior.ColorIndex = 15
Next ccc
End Sub

have a nice time with all these beautiful colors
Erik
 
Upvote 0
That works except it also colors the merged cells. I need to keep the merged cells original colors
 
Upvote 0
Erik

You mentioned 'you are interested in this too'

Does this mean you are interested in what my workbook does or interested in the answer to my question (because you've almost answered it)?[/quote]
 
Upvote 0
Mutrus,

Try this code:

Code:
Sub Macro1()
    Dim myRange As Range
    Dim y As Integer
    x = InputBox("Enter the Day (1-31).")
    If x = "" Then Exit Sub ' User pressed cancel button
    If IsNumeric(x) Then
        y = Rows("6:6").Find(What:=x, LookIn:=xlValues).Column
        Set myRange = Range(Cells(5, y), Cells(15, y))
        For Each c In myRange
            If c.MergeCells = True Then
                Else
                    c.Interior.ColorIndex = 15
            End If
        Next c
    End If
End Sub
 
Upvote 0
Mutrus, the technical explanation of what is happening is this: merged cells suck! They're much more trouble than they're worth. Before trying to figure out code to circumvent your problems, you might want to try this: unmerge your cells, and try formatting them to Format>Cells>Alignment>Horizontal>Center Across Selection. Practically the same results, without the hassle.

Barry
 
Upvote 0
Ahnold - perfect - thanks

Barry - I agree - your suggestion is noted thanks

Others - thanks
 
Upvote 0
mutrus,

To answer to your question of 10:40. I was interested in the solutions.
Barry, thanks for this solution!

bye,
Erik
 
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,944
Members
449,480
Latest member
yesitisasport

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