Library code snippets

Make cells bold using criteria

In column "A" put a "1" in cells 1 to 27. Put "2" in A28. Put any text in columns B & C 1 to 28. The macro will turn the cells at row 28 Bold. (By changing the position of 2, or adding additional 2's to column A, the other rows will also be made bold)

Sub TestMac()
   Dim c As Object
   
   For Each c In Range("a1:a28")
       If c.Value = 2 Then
           c.Offset(0, 1).Font.Bold = True
           c.Offset(0, 2).Font.Bold = True
       Else
           c.Offset(0, 1).Font.Bold = False
           c.Offset(0, 2).Font.Bold = False
       End If
   Next
End Sub

Comments

  1. 04 Sep 2003 at 15:41

    I'm having trouble trying do condition formatting based on a criteria that if the value in a range of cells is greater than the value in another value, make the colour red for example.  Here is code I attempted to do but I am getting errors:


    Sub CellChange()


       Dim rngLastPrice As Range
       Dim rngClose As Range
           Set rgLastPrice = ActiveCell.Range("H6:H46")
           Set rngClose = ActiveCell.Range("Q6:Q46")
               
           
               
           If rngLastPrice.Cells().Value > rngClose.Cells().Value Then
               rngLastPrice.Cells().Font.ColorIndex = 3
               With Selection.Interior
                              .ColorIndex = 44
                              .Pattern = xlSolid
               End With
           Else
               rngLastPrice.Cells().Select
               With Selection.Interior
                                   .ColorIndex = 10
                                   .Pattern = xlSolid
               End With
           End If
               
           
       
    End Sub



    All I want to do is if the value "Last Price" is > than "ClosePrice" turn the colour of the active cell green



    thanks


  2. 01 Mar 2002 at 07:10

    Or use Conditional formatting!


    Or if it must be VBA, why not


    Sub TestMac()
      Dim c As Range
       
      For Each c In Range("a1:a28")
         c.Range("A1:B1").Font.Bold = c = 2
      Next
    End Sub



  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Make cells bold using criteria.

Leave a comment

Sign in or Join us (it's free).

Neil Derek

Want to stay in touch with what's going on? Follow us on twitter!