Wednesday, February 18, 2009

Excel VBA: Looping through a range

The following microsoft excel VBA macro example demonstrates how to loop through all the cells in a range. This example uses the For Each...Next statement to search the word "Microsoft Excel VBA" in a range and changes its font style to bold. In this case, the range is from A1 to E5.

Sub ChangeFontStyle()
   Dim Cell As Range
  
   For Each Cell In Range("A1:E5")
       If LCase(Cell.Value) = "microsoft excel vba" Then
           Cell.Font.Bold = True
       End If
   Next Cell
End Sub


Related posts:

No comments:

Post a Comment