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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

688 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