Excel Macro-

Posted on 2004-11-10
Last Modified: 2010-05-02
I want to write a macro which will check whether in a column every row contents end in "END". If so colur that cell with red.

Eg If a cell contains - "YEAR-END" then it will be colured red. If a cell contains "END-YEAR" it will be left like that this has to be chhecked for all cels in Column B
Question by:michaelm702
    LVL 5

    Expert Comment

    You don't need a macro.

    Assuming that column B has your values that need testing ...

    Select all of Column B

    Add a conditional format to whatever cell you want to have change colour.

    Goto Format ... Conditional Formatting

    Change Cell Value Is to Formula Is

    Type the following ...


    Then click Format, select Patterns and choose a red fill.

    Click OK

    LVL 16

    Accepted Solution

    If you do particularly want a macro, you can use:

        Sub RedIfEnd()
            Dim rng As Range        

            For Each rng In Selection.Cells
                If Right(Trim(UCase(rng.Value)), 3) = "END" Then rng.Interior.Color = RGB(255, 0, 0)
            Next rng
        End Sub

    This will also omit any trailing spaces from the cell value (so it will turn red for 'this-end' and 'this-end   ' but not 'end-this' -- no quote marks, of course)


    LVL 16

    Expert Comment

    As far as I can see, either solution works fine...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now