Setting multiple row heights in VBA

Extivalis

New Member
Joined
Mar 21, 2024
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I've seen a few different options for setting a row height across and entire sheet/tab in VBA, but I haven't had luck with this (sorry if I'm just missing it):

I want to set all row heights in a specific sheet/tab to 15, unless there is data in Column A, for those rows I need to have the row height be AutoFit. If it makes a difference (and is possible), I'd also like to leave users with the ability to still manually adjust the row height after the fact without having to go in and remove a conditional formatting rule.

Thanks in advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I don't think you can set row heights with conditional formatting. Try this macro.

VBA Code:
Option Explicit

Public Sub Set_Row_Heights()

    Dim rowsRange As Range
    Dim thisRow As Range
    
    With ActiveSheet
        Set rowsRange = .Range(.Cells(.UsedRange.Row, .UsedRange.Column), .Cells(.UsedRange.Row + .UsedRange.Rows.Count - 1, .UsedRange.Column + .UsedRange.Columns.Count - 1))
    End With
    
    Application.ScreenUpdating = False
    
    For Each thisRow In rowsRange.EntireRow
        If IsEmpty(thisRow.Cells(, 1).Value) Then
            thisRow.RowHeight = 15
        Else
            thisRow.AutoFit
        End If
    Next
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
If it would be easier: if there's a straight forward way to use VBA to look through the whole tab/sheet and autofit the row height for any row with data in Column A, I could always just record a macro setting all the row heights to 15, then following with the autofit coding for data in Column A.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top