I'm taking on a project in which I've built a map of locations in which house inventory. On one sheet is the map and on another sheet would be inventory that hasnt moved in X number of days pulled from a query. What I'm wanting to do is highlight the location on the map with a red color that corresponds to the location containing old inventory.
Examples of each:
I attempted to do this using Conditional formatting but couldnt come up with a formula to accomplish this, I also wrote the following code hoping for the same results with no success (running this causes excel to crash):
Sub Highlight()
Dim Locations As Range
Dim Old_Inv As Range
Dim MyRange As Range
Dim MyRange2 As Range
Set Locations = Worksheets("Sheet3").Range("C4:CD71")
Set Old_Inv = Worksheets("Sheet2").Range("C2:C20000")
For Each MyRange In Locations
For Each MyRange2 In Old_Inv
If MyRange.Value = MyRange2.Value Then
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark2
End With
End If
Next MyRange2
Next MyRange
End Sub
Please note I have very little experience using VBA, sorry if this is way off the mark. Any thoughts or suggestions would be much appreciated
Locations
range and use theMatch
function (useWorksheetFunctions
to invoke it) to check if it exists inOld_Inv
. IfMatch
returns a number, change the colour to red – Zac