Excel VBA to Rotate Text to 90 Degrees (4 Easy Examples)

We will show 4 VBA code examples to rotate text to 90 degrees. We will use the following dataset for the examples.


Example 1 – Excel VBA Code to Rotate Text to 90 Degrees in a Fixed Cell

We’ll rotate cell B5.

Steps:

  • Go to the Sheet Name section and right-click on the active sheet name.
  • Choose the View Code option from the list.

Simple VBA Coode to Rotate Text to 90 Degrees in Excel

  • The VBA window will appear.
  • Choose the Module option from the Insert tab.

Simple VBA Coode to Rotate Text to 90 Degrees in Excel

  • The VBA command module will appear. We will write VBA code on the module.

  • Copy and paste the following VBA code in the command module.
Sub rotate_text_1()
Dim text_1 As Range
Set text_1 = Range("B5")
With text_1
    .Orientation = 90
End With
End Sub

Simple VBA Coode to Rotate Text to 90 Degrees in Excel

  • Run the VBA code by pressing F5.


Example 2 – VBA Code to Turn Text to 90 Degrees from Selection

Steps:

  • Press Alt + F11 to enter the VBA window.
  • Select Insert and choose Module.
  • Put the following VBA code on the command module.
Sub rotate_text_2()
Dim text_1 As Range
Set text_1 = Application.Selection
With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 90
        .ShrinkToFit = True
        .MergeCells = False
    End With
End Sub
  • Select the range of cells you want to rotate.

VBA Code to Rotate Text to 90 Degrees from Selection

  • Run the code with F5.
  • Choose the rotated rows.
  • Move the cursor between the cells and double-click the mouse button.

VBA Code to Rotate Text to 90 Degrees from Selection

Look at the dataset.


Example 3 – VBA Code to Rotate Text to 90 Degrees from User’s Input

Steps:

  • Hit Alt+F11 to enter the VBA window.
  • Go to Insert and select Module.
  • Copy the following VBA code and paste it onto the module.
Sub rotate_text_3()
Dim text_1 As Range
Set text_1 = Application.InputBox("Range", "Select a range", Type:=8)
With text_1
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 90
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
End Sub

Excel VBA to Rotate Text 90 Degrees from User’s Input

  • Press F5 to run the code.
  • A dialog box will appear to choose a range. We selected Range B5:B6 here.

Excel VBA to Rotate Text 90 Degrees from User’s Input

  • We want to fit texts on the cells. Choose Rows 5 and 6.
  • Move the cursor on the selection.
  • Double-click.

Look at the dataset. Texts of cells are rotated with proper presentation.

Read More: Excel VBA to Set Vertical Alignment


Example 4 – Excel VBA to Autofit Text and Rotate to 90 Degrees

Steps:

  • Hit Alt+F11 to enter the VBA window.
  • Select Insert and choose Module.
  • Put the VBA code below on the command module.
Sub rotate_text_4()
Dim text_1 As Range
Set text_1 = Range("B5:B6")
With text_1
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 90
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
  text_1.EntireRow.AutoFit
  text_1.EntireColumn.AutoFit
End Sub

Excel VBA to Autofit and Rotate to 90 Degrees

  • Press F5 to run the VBA code.


Download the Practice Workbook


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Alok Paul
Alok Paul

Alok Paul has completed his B.Sc. in Electronics and Telecommunication Engineering from East West University. He has been working on the ExcelDemy project for more than 2 years. He has written 220+ articles and replied to numerous comments. He is experienced in Microsoft Office, especially in Excel. He also led some teams on Excel and VBA content development. He has a keen interest in Advanced Excel, Data analysis, Excel Pivot Table, Charts, and Dashboard. He loves to research... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo