VBA - color the task, which has been sign by X

maxblack

New Member
Joined
Nov 15, 2016
Messages
36
Hello Collegues,

I need your help following idea. I have a table with employees where I insert, what they will be doing particular day. To make it more readable I have following idea:

When Perons 1 will choose her name, cells in row 2, where we have tasks, which have to done will be coloured. Which task should be coloured should be based on X inserted in row of that person. I try to figure it out how to do this using VBA.

I would be grateful for your support.
Thanks
max

21/04/2017
Task 1Task 2Task 3Task 4Task 5Task 6Task 7Task 8Task 9Task 10Task 11Task 12Task 13Task 14Task 15
P1X
P2XX
P3XXX
P4XXX
P5XXX
P6XX
P7XX
P8XX
P9XX
P10XX
P11XX
P12XX

<tbody>
</tbody>

I had no ide how to attach something.
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Edit: When Perons 1 will choose her name, cells in top row (Task 1, 2, 3, etc.) will be coloured based on X inserted in row of that person.
 
Upvote 0
Perhaps this:-
Select range of possible "X" cells approx:-"B2:P13"
On Ribbon select Conditional Formatting.
On drop down select, "Highlight Cellrules".
From DropDown Select "Equalto",
In Dropdown Box" place an :- X
Select colour from dropdown on right handside.
Click OK .
All cell with "X" are nowcoloured.
 
Upvote 0
Thanks MickG, my question was a little bit different, but thanks, probably I described it wrongly.

The result should be as example:

I select "Person 1" cell and then Task1, Task 12 and Task 14 are going to be highlighted on yellow.
Then I select "Person 2" cell and Tasks are changing into Task 2, Task 3 and Task 8. etc etc.

I hope its clear now.

Thanks
 
Last edited:
Upvote 0
Your logic appears to be you select "P1" (Person 1) in column "A" and the cells in that row Marked "X" are highlighted.
Meaning only the person selected will have that row highlighted, the remaining rows being not highlighted
Is that correct ???
 
Upvote 0
@MikeG,

I think OP wants that when selecting it we say "P1" (Person 1) in Column A, to all cells marked with "X", Task 2 be highlighted. So the headers from each "X".
If selecting "P2" then highlighted: Task 9 and Task 15
 
Last edited:
Upvote 0
@MikeG,

I think OP wants that when selecting it we say "P1" (Person 1) in Column A, to all cells marked with "X", Task 2 be highlighted. So the headers from each "X".
If selecting "P2" then highlighted: Task 9 and Task 15

Yes, exactly :) Thanks Ingolf
 
Upvote 0
Insert this code in sheet:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim MatrixRng As Range
    Dim LastColumn As Integer
    Dim Rng As Range
    LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
    Range("A1").CurrentRegion.Interior.Color = vbWhite
    If Not Intersect(Target, Range("A1:A13")) Is Nothing Then
        Set MatrixRng = Range(Target.Offset(0, 1), Target.Offset(0, LastColumn))
        For Each Rng In MatrixRng
            If Not IsEmpty(Rng) Then
                Rng.Interior.Color = vbYellow
            End If
        Next Rng
    End If
End Sub
 
Last edited:
Upvote 0

Unknown
ABCDEFGHIJKLMNOP
121/04/2017Task 1Task 2Task 3Task 4Task 5Task 6Task 7Task 8Task 9Task 10Task 11Task 12Task 13Task 14Task 15
2P1X
3P2XX
4P3XXX
5P4XXX
6P5XXX
7P6XX
8P7XX
9P8XX
10P9XX
11P10XX
12P11XX
13P12XX
Sheet14



If you want the headings to be colored then,

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim MatrixRng As Range
    Dim LastColumn As Integer
    Dim Rng As Range
    LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
    Range("A1").CurrentRegion.Interior.Color = vbWhite
    If Not Intersect(Target, Range("A2:A13")) Is Nothing Then
        Set MatrixRng = Range(Target.Offset(0, 1), Target.Offset(0, LastColumn))
        For Each Rng In MatrixRng
            If Not IsEmpty(Rng) Then
                Rng.Offset(-Rng.Row + 1, 0).Interior.Color = vbYellow
            End If
        Next Rng
    End If
End Sub
 
Upvote 0
Thanks Nishant94 its working, but I have some questions:

1. Now its changing the interior color of whole table into white. Is it possible to do not touch table colours as its more readable with colours?
2. As you noticed its one day table, for next days I would like to insert same tables under each other, but then the code will not be working. If I will prepare one sheet where I will have 5 tables-days I have to insert 5 codes one for each table, am I right? I could also copy paste tables on right and hide prior day - it will be working good, but the problem will be with changing colours.
3. may you explain a little bit your code I would like to understood it better, especially from If Not...

Thanks
max
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,859
Members
449,194
Latest member
HellScout

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