+ Reply to Thread
Results 1 to 3 of 3

Check and color a cell if ... (VBA)

  1. #1
    Registered User
    Join Date
    06-29-2010
    Location
    cambridge
    MS-Off Ver
    Excel 2003
    Posts
    1

    Check and color a cell if ... (VBA)

    Hi, I was wondering if I could get help with a VBA project I'm working on to write a macro script that will check the string within a cell to see if conditions are met and then color the cell if any of them are met.

    I have some programming experience, but I don't know the syntax of VBA very well. I'm having difficulty figuring out how to activate cells, shift down to test the next cell, etc.

    There are 10 conditions, mainly of 3 types.
    1) Is there a "Q" in the string
    2) Are there multiple "C"s in the string
    3) Are there more than 20 characters (ignore spaces) in the string

    Essentially the macro will select cell "i2", test the cell text (containing a string of capital letters and spaces) for the 10 conditions, and color the cell background red if any conditions are met. Then it will check i3, i4, i5,...i500. Then it will move to k2, k3, k4....k500. M...O...(increment by 2 letters) until AC2...AC500.

    My work so far:

    I have a variable defined for each letter (ex: Ccount), a total length variable for checking total length, and an errorcount variable will increment from 0 if any conditions are met, and the cell will turn red if errorcount is >0 at the end of the cycle for each cell. Then it should set everything back to 0 and redo the process.


    If someone could help with the outlining for the first 3 conditions, I can implement the others since they're very similar.


    I already have the functions written out for each condition, but since the program will be checking hundreds of cells for all 10, I figure a loop in a macro in VBA would be more elegant. However, if there are suggestions for using my current functions (lots of len() ) those might be useful instead.
    Last edited by cambridge; 07-15-2010 at 02:43 PM. Reason: Solved

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Check and color a cell if ... (VBA)

    Hello cambridge,

    That is a lot of conditions and a lot of cells to check. Each of the three conditions you mention require 3 separate methods to validate the condition. Here is an example...
    Please Login or Register  to view this content.

    If speed is an issue, I can write some routines using more advanced pattern matching techniques.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Check and color a cell if ... (VBA)

    Hi cambridge;
    Don't know if you're still looking for an answer.
    The thread isn't marked Solved, but I don't want to waste your time if you're satisfied with Leith's reply.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1