Consulting

Results 1 to 3 of 3

Thread: Is it possible to write vba code to create a conditional format on cells?

  1. #1
    VBAX Mentor
    Joined
    Aug 2010
    Posts
    457
    Location

    Is it possible to write vba code to create a conditional format on cells?

    Hi, everyone! I will like to know how to write vba code to firstly, identify various cells for example that have 42, and color those cells with the color red. I would like to be able to use a macro or vba code to this. Can this be done? If so, how can this be done? Do you have any samples?


    Thanks for your contributions

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Is there a reason you wouldn't just use CV?

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I would use CV, but for a simple macro try
    [vba]Sub Macro1()
    Application.ReplaceFormat.Interior.ColorIndex = 3
    Cells.Replace What:="42", Replacement:="42", LookAt:=xlPart, SearchOrder _
    :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=True
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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