Link to home
Start Free TrialLog in
Avatar of shieldsco
shieldscoFlag for United States of America

asked on

Excel VBA Format Text

I need to format multiple Columns A,D,I,L Text on all worksheets except for 2 (Invoice and Summary).
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Use this macro:
Sub Demo()

    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets
        With ws
            If .Name <> "Invoice Sheet" And .Name <> "Summary Sheet" Then
                .Range("A:A").Interior.Color = vbRed    ' or whatever formatting you want
                .Range("D:D").Interior.Color = vbGreen    ' or whatever formatting you want
                .Range("I:I").Interior.Color = vbCyan    ' or whatever formatting you want
                .Range("L:L").Interior.Color = vbBlue    ' or whatever formatting you want
            End If
        End With
    Next

End Sub

Open in new window

Avatar of shieldsco

ASKER

I get the following runtime error 1004 method range of object _worksheet failed on  .Range("A").NumberFormat = "@"

Code:
Sub Demo()

    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets
        With ws
            If .Name <> "Invoice Sheet" And .Name <> "Summary Sheet" Then
                .Range("A").NumberFormat = "@"
                .Range("D").NumberFormat = "@"
                .Range("L").NumberFormat = "@"
            End If
        End With
    Next

End Sub
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial