Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:19:44+00:00 2026-06-06T19:19:44+00:00

I’m new to StackOverflow and VBA. I am an Expert with all aspects of

  • 0

I’m new to StackOverflow and VBA. I am an Expert with all aspects of Excel except writing code in VBA from scratch.

What I am trying to do is apply an color from the index to the interior of a cell if it contains a specific term. Here is what I have:

Sub ConditionalFormatting()

Do Until ActiveCell = ""

If ActiveCell = "STAR DISTRICT" Then
ActiveCell.Interior.ColorIndex = 50
ElseIf ActiveCell = "STAR SCHOOL" Then
ActiveCell.Interior.ColorIndex = 50
ElseIf ActiveCell = "HIGH PERFORMING" Then
ActiveCell.Interior.ColorIndex = 43
ElseIf ActiveCell = "SUCCESSFUL" Then
ActiveCell.Interior.ColorIndex = 34
ElseIf ActiveCell = "ACADEMIC WATCH" Then
ActiveCell.Interior.ColorIndex = 38
ElseIf ActiveCell = "LOW PERFORMING" Then
ActiveCell.Interior.ColorIndex = 22
ElseIf ActiveCell = "AT RISK OF FAILING" Then
ActiveCell.Interior.ColorIndex = 18
ElseIf ActiveCell = "FAILING" Then
ActiveCell.Interior.ColorIndex = 3
Else: ActiveCell.Interior.ColorIndex = 1
End If

ActiveCell.Offset(1, 0).Select

Loop

End Sub

The options are:
Star District or School,
High Performing,
Successful,
Academic Watch,
Low Performing,
At Risk of Failing,
Failing

This code works for one column (except for the bottom two terms) but it will not work anywhere else in the worksheet. When I try it anywhere else, all of the Cells turn Black (or ColorIndex = 1) no matter what the cell contains.

Any help would be greatly appreciated.

Trenton

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:19:45+00:00Added an answer on June 6, 2026 at 7:19 pm

    Without seeing your input data in your Excel spreadsheet, it is hard to say exactly why this is true:

    This code works for one column (except for the bottom two terms) but it will not work anywhere else in the worksheet. When I try it anywhere else, all of the Cells turn Black (or ColorIndex = 1) no matter what the cell contains.

    However, String comparison by default in VBA is a binary comparison, meaning it will be case sensitive and you are comparing ActiveCell to various upper case strings. If your Excel Spreadsheet contains anything but all upper case, all of the tests will fail.

    You need to do one of 2 things. First, you can add Option Compare Text to the top of your code sheet. That will change all comparisons to Text instead of Binary comparisons.

    Or you can wrap each ActiveCell in a UCASE function, that will capitalize any value in the active cell before performing the comparison:

    If UCase(ActiveCell) = "STAR DISTRICT" Then
    ...
    ElseIf UCase(ActiveCell) = "STAR SCHOOL" Then
    ...
    ...
    ...
    End If
    

    EDIT:

    As you mentioned in your comments, the problem was trailing spaces in the cell values, the appropriate code fix is to wrap ActiveCell in a Trim function. And you can nest functions inside of each other like:

    If UCase(Trim(ActiveCell)) = "STAR DISTRICT" Then
    ...
    ElseIf UCase(Trim(ActiveCell)) = "STAR SCHOOL" Then
    ...
    ...
    ...
    End If
    

    This would trim any trailing and leading spaces from the value in ActiveCell then make it upper case to compare to your flagged value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.