Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Format Cells as Text in Excel


Bookmark and Share

This free Excel macro formats a selection of cells as Text in Excel. This macro applies the Text number format to cells in Excel. This means that all contents of a cell are treated as text and, though you can display numbers in the same cells, text is formatted to align to the left of a cell. This means that numbers with text formatting will appear on the left side of a cell.
Where to install the macro:  Module

Excel Macro to Format Cells as Text in Excel

Sub Format_Cell_Text()

Selection.NumberFormat = "@"

End Sub


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Multiple Text Format In Excel Cells - Excel

View Content
I'm writing now convertor from my own Report Component to Microsoft Excel
format and have a problem: cannot programmically change font and text format
for PARTS of text in cell. It's easy to do by hand, but how can I do it
programmically?

Please help me! I have to appear checkboxes and comboboxes in Excel sheet,
and decided to do it in following manner:

[x] CheckboxName,
where [x] - symbol with code 0xFD of Wingdings font.

Or, maybe, there are other ideas?

David Avsajanishvili


From Excel Cells To Special Text Format - Excel

View Content
Each value is in one cell in excel, but if I copy and paste to notepad, then everything moves, I really need this format as an input to a program, please some help!!!

Is a way how to have this format for a text file?

-155 -11 85-356 -6
-943 -21 -1 29 15
-55 -11-285 -16 -3

Conditionally Format Cells With Text With A Formula - Excel 2007 - Excel

View Content
I am trying to conditionally format cells that contain certain text. I have a formula that is working but it applies the formatting to the entire selection. How do I set the formatting up to only apply the formula rule to the cells that have the true value?

Long Text Displays As ### When Format=text, Ok When Format=general, But Xmlmap Resets Format To Text - Excel

View Content
Hi,
I have a cell in a worksheet that contains long text (500 characters). It has Word wrap set. The data gets displayed fine if the cell format is General. But if the format is set to Text, then the data gets displayed as #######

Here's the problem. I'm loading data for this cell using an XML Map (by calling ImportXML from VB code). This seems to automatically reset the cell format to text. In the XML Map, I've mapped this field using the following definition:


Currently the workaround I've done is to reset the cell format in VB code after importing the XML Map, as follows:
Range("Comments").NumberFormat = "General"

Is there a better way to solve this? I would like to avoid writing this kind of code, if possible.

Thanks,
Sam

Format Cells As Text - Excel

View Content
Hello,

I hope someone can help i have a very long sheet with numbers in some cells and number sfollowed by a letter in others i have right clicked to format as text but the system i am uploading the information into does not recognise this formating until i have opened the cell in excel and hit return. This would not be so bad for a few cells but i have loads. Is there a quicker way?

Text Format Of Cells - Excel

View Content
Here is another simple one that I just can not whip or find the answer to in the help files.

I have merged 5 cells together. They are formatted for text, center allign, word wrap. Some times one line of text will do and another 2 or 3 lines will be necessary. I want the merged cells to expand down the page as lines are added through word wrap. They currently expand upwards and behind the frozen pane at top of page.

When expanding I want the whole row and it's other cells to expand to match the cell with text. Make sense?

Format Text Across Cells - Excel

View Content
If I copy a 10 line paragraph of text from the internet and paste it into
Excel, the text is all placed in a single cell. In Lotus I would then use \
Range Justify to wrap the text across several columns and down as many lines
as it needed.

Edit Fill Justify appears to do the same in Excell but only accepts about
256 characters and so deletes over half the text. Can you increase this
limit or is there another way?

Merging cells aeems to be cumbersome and inflexible. How do you adjust the
size of the box after you have created it.

Any ideas would be much appreciated




Format Cells Only That Have Text ? - Excel

View Content
Sorry viewers, I seem to have a lot of questions today...

In a range B12:I56, i want the users to only format cells, ie add a colour pattern to the cells if there is text in the cell. If the cell is blank then I want to prevent them from formatting

For additional information, the cells are formulated to return a value or a ""


Thank you

Format Text In Cells Not To Print Out - Excel

View Content
I have a spread sheet that I have used "check boxes" in column E. I formated each check box to represent a cell (E8, E9, E10, etc) The cell shows true if the check box is checked and false if not checked. Here is my problem. When I print the sheet, the True and False results print behind the check box. I want to [b]stop the "True or False" results from printing. How do I do this?

Vba Userform: Format Cells In Text Box - Excel

View Content
Hi all,

I'm writing codes for a userform, in which people have to enter various data in various text boxes. E.g. numbers, %'s, dates or text.

What I now want is that
- when they have to enter a date, they can only type the date in the form: dd/mm/yyyy
- For numbers, they can enter or e.g. 2000 or 2000,50, in this case in my table it should appear as 2.000,00 or 2.000,50 respectively
- for %, that in the textbox the '%' symbol is already present, and that they have to type the number before the % symbol

Would that be possible...?

Already thanks a lot!!!!




The codes I now have is the following:


Private Sub Userform_Initialize()

TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox13.Value = ""
ComboBox1.Clear
ComboBox2.Clear

With ComboBox1
.AddItem "EUR"
.AddItem "USD"
.AddItem "GBP"
.AddItem "JPY"
.AddItem "CHF"
.AddItem "PLZ"
.AddItem "SEK"
.AddItem "DKK"
End With

With ComboBox2
.AddItem "No"
.AddItem "Flex"
.AddItem "Fix"
End With

TextBox1.SetFocus

End Sub



Private Sub CommandButton1_Click()

Unload Me

End Sub




Private Sub OKCommandButton_Click()

Sheets(4).Activate

emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2

'Export Data to worksheet
Cells(emptyRow, 2).Value = TextBox1.Value
Cells(emptyRow, 3).Value = ComboBox1.Value
Cells(emptyRow, 4).Value = TextBox2.Value
Cells(emptyRow, 5).Value = TextBox3.Value
Cells(emptyRow, 6).Value = TextBox4.Value
Cells(emptyRow, 7).Value = TextBox5.Value
Cells(emptyRow, 8).Value = ComboBox2.Value
Cells(emptyRow, 18).Value = TextBox6.Value
Cells(emptyRow, 19).Value = TextBox7.Value
Cells(emptyRow, 20).Value = TextBox8.Value
Cells(emptyRow, 21).Value = TextBox9.Value
Cells(emptyRow, 22).Value = TextBox10.Value
Cells(emptyRow, 23).Value = TextBox11.Value
Cells(emptyRow, 24).Value = TextBox12.Value
Cells(emptyRow, 25).Value = TextBox13.Value

Cells(emptyRow, 1).Value = UserForm2.Caption

Unload Me

End Sub

Random Tutorials
FV() Find the Future Value of Cash Today
         -Savings/Retirement Plan Calculations

(Intermediate)
Lookups With MATCH() and INDEX() Functions
(Intermediate)
Link Cells Between Worksheets
(Easy)
Consolidate & Combine Data from Separate Worksheets or Workbooks(Excel Files)
(Intermediate)
How to record a Macro - And what One is
(Easy)
Assign a Macro to a Button and Toolbar
(Intermediate)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com