REAL-TIME

VBA Projects

Full Access with Source Code
  • Designed and Developed by PNRao

  • Full Access with VBA Source Code

  • Well Commented Codes Lines

  • Creative and Professional Design

Effortlessly
Manage Your Projects

120+ Project Management Templates

Seamlessly manage your projects with our powerful & multi-purpose templates for project management.

120+ PM Templates Includes:
  • 50+ Excel Templates

  • 50+ PowerPoint Templates

  • 25+ Word Templates

Share Post

Description:

Some times we may enter the data into cells more than it’s width. In this case we can not able to see entire text. So we can change row height and Column width using excel using VBA. So that we can see entire data in that cell. When you have more lengthy data in cells, you can Auto Adjust Column Width or Row Height in Excel VBA to show the entire data. So that users can see the entire data in the cells. We will see with Examples.

Changing Row Height in Excel VBA

Change Row Height in Excel VBA
We can change row height in Excel using RowHeight Property of a Row in VBA. See the following example to do it.

Examples

The following example will change the height of the 3rd Row to 25.

Sub sbChangeRowHeight()

'Changing the 3rd row Height
Rows(3).RowHeight = 25

End Sub

We can also set the height for multiple rows, the following example will change the height of the 3rd to 20th row height to 25.

Sub sbChangeRowHeightMulti()

'Changing the 3rd-25the row Height
Rows("3:25").RowHeight = 25

End Sub
Instructions:
  1. Open an excel workbook
  2. Press Alt+F11 to open VBA Editor
  3. Insert a Module for Insert Menu
  4. Copy the above code and Paste in the code window
  5. Save the file as macro enabled workbook
  6. Press F5 to execute itit

Changing Column Width in Excel VBA

Change Column Width in Excel VBA
We can change column width in Excel using ColumnWidth Property of a Column in VBA. See the following example to do it.

In this Example I am changing the Column B width to 25.

Sub sbChangeColumnWidth()

Columns("B").ColumnWidth = 25

End Sub

Examples

We can also set the column width for multiple columns at a time, see this Example I am changing the Column B to E width to 25.

Sub sbChangeColumnWidthMulti()

Columns("B:E").ColumnWidth = 25

End Sub
Instructions:
  1. Open an excel workbook
  2. Press Alt+F11 to open VBA Editor
  3. Insert a Module for Insert Menu
  4. Copy the above code and Paste in the code window
  5. Save the file as macro enabled workbook
  6. Press F5 to execute it

Auto Adjust Column Width and Row Height using Excel VBA

Auto Adjust Column Width - Row Height in Excel VBA
We can use AutoFit method of Columns and Rows in Excel using VBA to Auto Adjust the rows and Columns.

Examples

Code to Auto Adjust Column Width

Following are the example to show you how to do this.

Sub sbAutoAdjustColumnWidth()

    Columns(2).AutoFit

End Sub
Code to Auto fit Row Height

Following are the example to show you how to do this.

   Sub sbAutoAdjustRowHight()
   Rows(2).AutoFit
End Sub
Instructions:

Follow the instructions below to test the codes above.

  1. Open an excel workbook
  2. Press Alt+F11 to open VBA Editor
  3. Insert a Module for Insert Menu
  4. Copy the above code and Paste in the code window
  5. Save the file as macro enabled workbook
  6. Press F5 to execute it
Effortlessly Manage Your Projects and Resources
120+ Professional Project Management Templates!

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Save Up to 85% LIMITED TIME OFFER
Project Management Templates

All-in-One Pack
120+ Project Management Templates

Essential Pack
50+ PM Templates

Excel Pack
50+ Excel PM Templates

PowerPoint Pack
50+ Excel PM Templates

MS Word Pack
25+ Word PM Templates

Ultimate Project
Management Template
Ultimate Resource
Management Template
Project Portfolio
Management Templates
Categories: Excel VBATags: Last Updated: June 17, 2022

4 Comments

  1. Koert penne March 29, 2016 at 2:35 PM

    I wanted the row height for content of one column, regardsless what was in the other columns. I did it as follows:

    Sub rowheight_one_column()

    Column = InputBox(“Hoeveelste kolom?”) + 0

    Rows(20).Delete

    For x = 4 To 13
    Cells(20, Column) = Cells(x, Column)
    Rows(20).AutoFit
    hoogte = Cells(20, Column).RowHeight
    Rows(x).RowHeight = hoogte
    Next x

    Rows(20).Delete

    End Sub

  2. Sathish October 26, 2016 at 11:39 AM

    Please help me for auto fit the entire sheet1

  3. Jack February 21, 2017 at 7:43 PM

    where have you declared your Variables, It does confuse people when your code is not neat and is exposed on the Internet where everybody does search and get stuck.

  4. dskar April 13, 2017 at 7:10 AM

    the difference between writing the code in code window and a module?

Leave A Comment