VBA Change Format of All Cells in a Workbook

B

benatom

With VBA I would like to change the format of all cells in all
worksheets of a workbook to 'General' or 'Text'. How can this be
done? Thanks.
 
J

JE McGimpsey

One way:

Dim ws As Worksheet
For Each ws in ActiveWorkbook.Worksheets
ws.Cells.NumberFormat = "General" ' or "@" for Text
Next ws
 
J

Joel

Sub test()

For Each sht In Sheets

sht.Cells.NumberFormat = "General"

Next sht


End Sub


or

Sub test()

For Each sht In Sheets

sht.Cells.NumberFormat = "@" 'for text

Next sht


End Sub
 
R

Rick Rothstein

This should do it

Sub ChangeWorkbookFormat()
Dim WS As Worksheet
For Each WS In Worksheets
WS.Range("1:" & WS.Rows.Count).NumberFormat = "General"
Next
End Sub

Use "@" instead of "General" if you want the Text format.
 
R

Rick Rothstein

As others have pointed out, Cells is better to use than my
Range("1:"&WS.Rows.Count).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top