Solved

Excel VBA Format Text

Posted on 2014-04-07
3
364 Views
Last Modified: 2014-04-07
I need to format multiple Columns A,D,I,L Text on all worksheets except for 2 (Invoice and Summary).
0
Comment
Question by:shieldsco
  • 2
3 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39982937
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

0
 

Author Comment

by:shieldsco
ID: 39982963
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
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39982974
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").NumberFormat = "@"
                .Range("D:D").NumberFormat = "@"
                .Range("I:I").NumberFormat = "@"
                .Range("L:L").NumberFormat = "@"
            End If
        End With
    Next

End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Keyboard shortcuts for Back & Forward QAT arrows in Excel 3 56
Excel case statements 3 24
Fixing a embedded format 7 29
ADD New Entries 7 15
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now