Vlookup + format

Posted on 2012-03-15
Last Modified: 2012-03-16

I have attached a WB.

I would like some vb code to hightlight rows red or green in the ASPA tab dependant on whether or not their Sedol is present in the tab "Phoenix"

So comparing Col A in ASPA against Col B in Phoenix

I have manually highlighted a few lines that would be green and would be red after the code has run

Question by:Seamus2626
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 15

Expert Comment

ID: 37724500
I guess you wouldnt even need code, just a slightly more advanced conditional formatting.

E.g. like this


Author Comment

ID: 37724652

Where is the conditional formatting stored? I cant see it anywhere?

LVL 81

Accepted Solution

byundt earned 500 total points
ID: 37727487
Conditional formatting is stored with the worksheet. Depending on the version of Excel, you may need to use named ranges to avoid referring to a different worksheet--Conditional Formatting didn't permit direct references to other worksheets before Excel 2010 (I believe).

Here is a macro that works in Excel 2003 and 2010. It creates a named range for Phoenix worksheet column B, then applies conditional formatting to ASPA worksheet data.
Sub SedolConditionalFormatting()
Dim nm As Name
Dim rg As Range
Application.ScreenUpdating = False
On Error Resume Next
Set nm = ThisWorkbook.Names("PhoenixSedol")
On Error GoTo 0
If nm Is Nothing Then
    ThisWorkbook.Names.Add "PhoenixSedol", RefersTo:="=Phoenix!$B:$B"
End If
Set rg = Worksheets("ASPA").Range("A1").CurrentRegion
Set rg = rg.Offset(1, 0).Resize(rg.Rows.Count - 1)
With rg
    .FormatConditions.Add Type:=xlExpression, Formula1:="=AND($A2<>"""",COUNTIF(PhoenixSedol,$A2)>0)"
    .FormatConditions(1).Interior.ColorIndex = 4
    .FormatConditions.Add Type:=xlExpression, Formula1:="=AND($A2<>"""",COUNTIF(PhoenixSedol,$A2)=0)"
    .FormatConditions(2).Interior.ColorIndex = 3
End With
End Sub

Open in new window


Author Closing Comment

ID: 37728821
Thank you!

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question