Excel / VB - How do I loop through each row/column and do formatting based on the value?

Posted by Johnny 5 on Stack Overflow See other posts from Stack Overflow or by Johnny 5
Published on 2010-04-12T21:18:12Z Indexed on 2010/04/12 21:23 UTC
Read the original article Hit count: 255

Filed under:
|
|

Here's what I need to do:

1) Loop through every cell in a worksheet 2) Make formatting changes (bold, etc) to fields relative to each field based on the value

What I mean is that if a field has a value of "foo", I want to make the field that is (-1, -3) from it bold, etc. I tried to do this with the following script with no luck.

Thanks Johnny

Pseudo Code to Explain:

For Each Cell in WorkSheet
    If Value of Cell is 'Subtotal'
        Make the cell 2 cells to the left and 1 cell up from here bold and underlined
    End If
End ForEach

The Failed Macro (I don't really know VB at all):

Sub Macro2()
'
'
'
Dim rnArea As Range
Dim rnCell As Range

Set rnArea = Range("J1:J2000")

    For Each rnCell In rnArea
        With rnCell
            If Not IsError(rnCell.Value) Then
                Select Case .Value
                    Case "000 Total"
                        ActiveCell.Offset(-1, -3).Select
                        ActiveCell.Font.Underline = XlUnderlineStyle.xlUnderlineStyleSingleAccounting
                End Select
            End If
        End With
    Next
End Sub

© Stack Overflow or respective owner

Related posts about vbscript

Related posts about visual-basic