VBA example - Excel 2007: wrap text in Sheet

VBA code to wrap text in Sheet

When a long text is placed in a single column that its width is less than the number of characters in the text, the text expands to other columns. This may not be what you want. To make the text fit in the column, you need to wrap it. In the sample text below, most of the cells contain text that expand to other columns. To make the text wrapped, you can write a few lines of Excel VBA code.

Wrapping text with VBA code
Excel 2007 tutorial
VBA programming tutorial
VBA has two common types arrays: 1D and 2D Arrays
Excel VBA
In VBA there are five types of loop statements
Learn VBA
Learn Excel VBA
VBA filtering data
VBA function
Microsoft Excel 2007
Excel sample code
One-dimensional array of Excel VBA
two-dimensional array in Excel VBA

To run this example VBA code, you will need a Form, and a CommandButton. You may copy or type the sample text above in to your current worksheet.

VBA for Excel: VBA code to wrapt text in Excel sheet

VBA code for this example:

Option Explicit Private Sub CommandButton1_Click()    
Call textWrap

End Sub  

Sub textWrap()    
Dim i As Integer
i = 1
While Range("A" & i) <> ""
Range("A" & i).WrapText = True
i = i + 1

End Sub


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.