PDA

View Full Version : Formatting a column into "text"



sathishesb
02-02-2011, 02:02 AM
Hi guys,

I need to format column A of Sheet1, Sheet2 into "TEXT" using VBA code..

Please give me some example code.
Plzzz help me guys:help

Rob342
02-02-2011, 03:26 AM
Hi try this it should work.


Private Sub Workbook_Open()
Columns("A:A").Select
Selection.NumberFormat = "@"
Sheets("Sheet2").Select
Columns("A:A").Select
Selection.NumberFormat = "@"
End Sub

frank_m
02-02-2011, 03:57 AM
Don't need the select's though..
Private Sub Workbook_Open()
Sheets("Sheet1").Columns("A:A").NumberFormat = "@"
Sheets("Sheet2").Columns("A:A").NumberFormat = "@"
End Sub Plus one of Excels quirks worth mentioning here is that changing the formatting of a cell to text that already contains a value such as numeric, usually will remain numeric for all intents and purposes that you might need the value for, until you either select each individual cell in the column and press F2 (I think it is), or possibly just the enter key. -- You can get around that by looping through used range in the column with a command similar to aCell.Value = aCell.Value - Or use a helper column with a formula. - Give a shout if that is an issue.