ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Change Format of All Cells in a Workbook (https://www.excelbanter.com/excel-programming/422033-vba-change-format-all-cells-workbook.html)

[email protected]

VBA Change Format of All Cells in a Workbook
 
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.

JE McGimpsey

VBA Change Format of All Cells in a Workbook
 
One way:

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



In article
,
wrote:

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.


joel

VBA Change Format of All Cells in a Workbook
 
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


" wrote:

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.


Rick Rothstein

VBA Change Format of All Cells in a Workbook
 
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.

--
Rick (MVP - Excel)


wrote in message
...
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.



Rick Rothstein

VBA Change Format of All Cells in a Workbook
 
As others have pointed out, Cells is better to use than my
Range("1:"&WS.Rows.Count).

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
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.

--
Rick (MVP - Excel)


wrote in message
...
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.





All times are GMT +1. The time now is 01:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com