Highlighting cells.

Tom.Jones

Well-known Member
Joined
Sep 20, 2011
Messages
509
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Mobile
Hi,

In Sheet 1 is a calendar. Each cell is once formatted to show only numbers from 1 to 31 (obviously, depending on the last day's month may be 28, 29, 30 or 31).
In Sheet 2 in column A starting with A2 some data are passed, and in column B are the names of those data.
I would like to be able to put certain colors in certain cells in Sheet 2 (say in Column C) and the data in Column A be highlighted in the same color in the Sheet 1 calendar.

Let's say that in A2 sheet 2, it is 01.02.2019, in B2 is the name of that day and in C2 I put the red color. I would like the calendar date of 01.02.2019 (dd.mm.yyyy) to be colored in red.
Because there is a lot of data I would like to highlight I would like to not use Condition Formatting, but a VBA code.

Is that possible?
Thank you.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Can you post a screen shot of what your data looks like? Section B at this link has instructions on how to post a screen shot: https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html Alternately, you could upload a copy of your file to a free site such as www.box.com. or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
@Tom.Jomes
You cannot post images to the board.
Please use one of the add-ins available here to post some sample data
 
Upvote 0
Thanks mumps and Fluff.

Yes, I have seen that I can not post pictures, but unfortunately I can not install anything on my computer due to company policies.
I do not know what I can do.

Let's try to simplify the problem.
If in Sheet 2, there are 3 calendar dates (say 01.02.2019, 19.04.2019 and 27.05.2019) and the adjacent cells are filled in red.
And in sheet 1 there are more data, and among those data are those in the sheet2.
Using a VBA code, I want to highlight those cells in Sheet 1, which contains the data in Sheet 2 (coloring them in red).

Thanks.
 
Last edited:
Upvote 0
Try:
Code:
Sub colorCells()
    Application.ScreenUpdating = False
    Dim LastRow As Long, rng As Range, fRng As Range
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In Sheets("Sheet2").Range("A2:A" & LastRow)
        Set fRng = Sheets("Sheet1").Range("A:A").Find(rng, LookIn:=xlValues, lookat:=xlWhole)
        If Not fRng Is Nothing Then
            fRng.Interior.ColorIndex = rng.Offset(0, 1).Interior.ColorIndex
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Data in Sheet 1 are like:

2019
JanFebMarEvent 1
qeWIwABH3t8jfin8wAAAAAElFTkSuQmCC
<tbody> </tbody>
If in DV is Event 1 then show ONLY date in RED
MTuWThFSSMTuWThFSSMTuWThFSSIf in DV is Event 2 then show ONLY date in Orange
123456123123and so on…
789101112134567891045678910
141516171819201112131415161711121314151617In B6 is first of January
212223242526271819202122232418192021222324
28293031252627281
2325262728293031
456789101234567
AprMaiJun
MTuWThFSSMTuWThFSSMTuWThFSS
1234567293012345272829303112
89101112131467891011123456789
151617181920211314151617181910111213141516
222324252627282021222324252617181920212223
29301234527282930311224252627282930
678910111234567891234567
JulAugSep
MTuWThFSSMTuWThFSSMTuWThFSS
123456729303112342627282930311
8910111213145678910112345678
15161718192021121314151617189101112131415
222324252627281920212223242516171819202122
2930311234262728293031123242526272829
567891011234567830123456
OctNovDec
MTuWThFSSMTuWThFSSMTuWThFSS
30123456282930311232526272829301
78910111213456789102345678
14151617181920111213141516179101112131415
212223242526271819202122232416171819202122
28293031123252627282930123242526272829
456789102345678303112345
<colgroup><col width="5" style="width: 4pt; mso-width-source: userset; mso-width-alt: 170;"> <col width="22" style="width: 17pt; mso-width-source: userset; mso-width-alt: 796;" span="7"> <col width="5" style="width: 4pt; mso-width-source: userset; mso-width-alt: 170;"> <col width="22" style="width: 17pt; mso-width-source: userset; mso-width-alt: 796;" span="7"> <col width="5" style="width: 4pt; mso-width-source: userset; mso-width-alt: 170;"> <col width="22" style="width: 17pt; mso-width-source: userset; mso-width-alt: 796;" span="7"> <col width="5" style="width: 4pt; mso-width-source: userset; mso-width-alt: 170;"> <col width="58" style="width: 43pt; mso-width-source: userset; mso-width-alt: 2048;"> <col width="73" style="width: 55pt; mso-width-source: userset; mso-width-alt: 2588;" span="2"> <col width="290" style="width: 218pt; mso-width-source: userset; mso-width-alt: 10325;"> <tbody> </tbody>

and in sheet2

EventsStartEndColor
Event 108.01.201911.01.2019
Event 225.02.201928.02.2019
Event 307.02.201910.02.2019
Event 418.03.201927.03.2019
Event 501.04.201905.04.2019
Event 627.05.201927.05.2019
<colgroup><col width="64" style="width: 48pt;"> <col width="78" style="width: 58pt; mso-width-source: userset; mso-width-alt: 2759;"> <col width="77" style="width: 58pt; mso-width-source: userset; mso-width-alt: 2730;"> <col width="64" style="width: 48pt;"> <tbody> </tbody>

Now you can see how is data.
 
Upvote 0
2019DV
JanFebMarEvent 1
MTuWThFSSMTuWThFSSMTuWThFSS
311234562829303112325262728123
789101112134567891045678910
141516171819201112131415161711121314151617
212223242526271819202122232418192021222324
282930311232526272812325262728293031
45678910456789101234567
AprMaiJun
MTuWThFSSMTuWThFSSMTuWThFSS
1234567293012345272829303112
89101112131467891011123456789
151617181920211314151617181910111213141516
222324252627282021222324252617181920212223
29301234527282930311224252627282930
678910111234567891234567
JulAugSep
MTuWThFSSMTuWThFSSMTuWThFSS
123456729303112342627282930311
8910111213145678910112345678
15161718192021121314151617189101112131415
222324252627281920212223242516171819202122
2930311234262728293031123242526272829
567891011234567830123456
OctNovDec
MTuWThFSSMTuWThFSSMTuWThFSS
30123456282930311232526272829301
78910111213456789102345678
14151617181920111213141516179101112131415
212223242526271819202122232416171819202122
28293031123252627282930123242526272829
456789102345678303112345
<colgroup><col width="22" style="width: 17pt; mso-width-source: userset; mso-width-alt: 796;" span="7"> <col width="5" style="width: 4pt; mso-width-source: userset; mso-width-alt: 170;"> <col width="22" style="width: 17pt; mso-width-source: userset; mso-width-alt: 796;" span="7"> <col width="5" style="width: 4pt; mso-width-source: userset; mso-width-alt: 170;"> <col width="22" style="width: 17pt; mso-width-source: userset; mso-width-alt: 796;" span="7"> <col width="5" style="width: 4pt; mso-width-source: userset; mso-width-alt: 170;"> <col width="58" style="width: 43pt; mso-width-source: userset; mso-width-alt: 2048;"> <col width="73" style="width: 55pt; mso-width-source: userset; mso-width-alt: 2588;"> <tbody> </tbody>

In AA4 I put a DV with Event1 to 6

If is more easy in this way ...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,018
Members
449,203
Latest member
tungnmqn90

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