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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now