Library code snippets
Make cells bold using criteria
By Neil Derek, published on 26 Feb 2002
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
Related articles
Related discussion
-
Searching for several parameters with one dropdown selection
by egallen (1 replies)
-
VBA macro Help-plzzzzzzzzzzzzzzzzzzzzzz
by Uncle (2 replies)
-
Enable Formula Audting in an Excel Workbook where all the sheets are protected
by raviarul (0 replies)
-
Listing table in Access VIA code
by merkava (1 replies)
-
How to deal with the brackets?
by jitender.gupta007 (1 replies)
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
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
This thread is for discussions of Make cells bold using criteria.