Match multiple ranges and fill interseting cell color

wizard4all

New Member
Joined
Mar 10, 2006
Messages
3
Hello,

I would like to use vb to fill a cell with color when the intersection of multiple ranges matches, all being dates. Example, lookup range A1:B4 and B1:B4 for matches in C1:F1. If A is empty then it would still look to fill the one B date match.

http://imgur.com/2cpZD

I know I can do this with conditional formatting but i am unable to overwrite the color in that case. I will be loading a sheet with multiple dates and would like to just run a macro due to the volume of data I have and the need to overwrite after the initial macro run.

Appreciate any help!

Thank you!!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Welcome to the mrexcel board!

Assuming the dates are real dates and not just text, try this in a copy of your workbook.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> ColourCells()<br>    <SPAN style="color:#00007F">Dim</SPAN> lHeaderStart <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, lRowStart <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, lRowLength <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, lAdate <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> rCel <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    lHeaderStart = Range("C1").Value<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> rCel <SPAN style="color:#00007F">In</SPAN> Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row)<br>        lAdate = IIf(rCel.Value = "", rCel.Offset(, 1).Value, rCel.Value)<br>        lRowStart = lAdate - lHeaderStart + 2<br>        lRowLength = rCel.Offset(, 1).Value - lAdate + 1<br>        rCel.Offset(, lRowStart).Resize(, lRowLength).Interior.ColorIndex = 3<br>    <SPAN style="color:#00007F">Next</SPAN> rCel<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>


Here's the results for me.

Excel Workbook
ABCDEFGH
1StartEnd28-Feb1-Mar2-Mar3-Mar4-Mar5-Mar
228-Feb1-Mar
31-Mar3-Mar
44-Mar
51-Mar4-Mar
Colour Cells
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,379
Members
452,907
Latest member
Roland Deschain

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