Excel Tutorial: Use VBA to instantly change row height based on value entered in worksheet cell
Вставка
- Опубліковано 11 лип 2024
- // FREE Excel E-book "Record Your First Macro"
→ www.launchexcel.com/record-yo...
// Recommended Excel Courses //
1. Launch Excel Macros & VBA School: go.launchexcel.com/macros-vba...
2. Excel Campus Elevate Program: go.launchexcel.com/excel-camp...
3. My Online Training Hub Dashboards: go.launchexcel.com/moth-dashb...
4. Coursera Excel Specialisation: go.launchexcel.com/coursera-e...
5. Coursera Everyday Excel: go.launchexcel.com/coursera-e...
6. Coursera Excel Data Visualisation: go.launchexcel.com/coursera-d...
// Recommended Excel Templates //
If you are looking for pre-built, easy to use spreadsheets, check out Simple Sheets.
go.launchexcel.com/simple-she...
They have Excel templates covering cash flow planning, invoices, expense reports, personal budgets, and more!
--
// EPISODE NOTES
In this tutorial video we look at how to automatically change row height by changing the value of a cell on your Excel worksheet using the built-in programming language VBA (Visual Basic for Applications).
We use a Worksheet_Change event to drive the automatic update.
I walk through two sample VBA Subroutines.
VBA Sub 1 - Automatically changes row height for ONE row.
VBA Sub 2 - Automatically changes row height for MANY rows.
--
// VIDEO TIMINGS
0:00 - Introduction
0:41 - Viewer Request Explained
2:00 - Worksheet Change Macro
4:15 - VBA Sub 1 Update_Row_Height
7:03 - How to Enter Worksheet Change Events (VBA Editor)
9:59 - Demo: Multiple Rows
10:51 - VBA Sub 2 Update_Row_Height_Range1
14:01 - Test Subroutines
15:40 - Outro
--
// DOWNLOAD WORKBOOK FOR THIS TUTORIAL
Please follow these instructions to learn from the workbook download:
▸ Download the sample Excel workbook: www.launchexcel.com/media/sam...
▸ Open the workbook and make sure to enable macros
▸ Press ALT + F11 to open the VBA Editor
▸ Use F8 to step through the code one line at a time
▸ I suggest you adapt this to your own needs... just copy and paste the code, then change the code to work for you
▸ If you have a viewer request, leave me a comment below and I'll try to solve your problem in a new video
--
// REFERENCES
Excel Version: 2016 (used in video)
--
// VISIT MY WEBSITE
For more tutorials on Microsoft Excel and VBA visit the website
→ www.launchexcel.com
DOWNLOAD WORKBOOK → www.launchexcel.com/media/samples/VBA/20180315-Change-Row-Height.xlsm
If you're totally new to Excel Macros & VBA... get my FREE e-book at this link:
DOWNLOAD EBOOK → launchexcel.lpages.co/first-macro-ebook
Leave comments with any questions you have...
And click on the LIKE button if you found this video helpful.
Thanks for supporting my channel!
What about changing column width instantly base on value sir.. thanks
Very nice! I used this but used other functions to get variable height of cells like (LEN) IF and Max to get the cell in a row that requires the most height. Thank you
Great!
This is very helpful and was wondering if you could expandit a little further to have different row heights for a number of rows?
I have an application where I would need to control the row heights of 10-15 rows with varying heights.
Is this possible?
Hi Dan, yes you can expand the functionality by adding new lines in the Select Case statement (9:10)
Select Case [variable]
Case [condition 1]
[Statement 1]
Case [condition 2]
[Statement 2]
Case [condition n]
[Statement n]
Case Else
[Statement else]
End Select
You can choose different cells as your condition in each "Case" line. And the code after each "Case" line will control which row height you want to change.
Hi, this video is very useful, unfortunately I am getting "Compile error, Expected list Separator or )"
Hi, I am new to Visual Basic and understand the basics of this tutorial however should i wish to determine the row height from a piece of text in a drop down list, for example one choice being "Basic" and the other being "Advanced" how do i assign the row height value of 0 to basic and 14.4 to Advanced.
You could hard code this into VBA by using a Worksheet Change Event and a routine that specifically checks for a change to a specific cell (in this case, the cell with the two data validation options; ‘Basic’, ‘Advanced’). This can be achieved with an ‘If Not Intersect(Target, Range(“”)) Is Nothing Then’. You could use an if statement or a select case statement within this to adjust row height based on the cell value and the corresponding, pre-defined row height for that particular value. If you wanted this to be more dynamic you could incorporate a table that comprises of the text string and the corresponding row height that you want to use for that value and reference/lookup this.