Adjusting row height without unhiding currently hidden rows

Deverti

Board Regular
Joined
Sep 5, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hey there

Im using the code below to change row heights but it always unhides some adjacent rows.

Would be neat if somebody can tell me how to implement something like SpecialCells so it keeps those hidden cells in peace.
.SpecialCells(xlCellTypeVisible)

VBA Code:
Sub AdjustEmptyRowHeight()
Dim i As Integer
Dim rng As Range
Dim lRow As Long

    lRow = ActiveSheet.UsedRange.rows(ActiveSheet.UsedRange.rows.Count).Row

        For i = 1 To lRow Step 1
            If WorksheetFunction.CountA(rows(i)) = 0 Then
                If rng Is Nothing Then
                  Set rng = rows(i)
                Else
                  Set rng = Union(rng, rows(i))
                End If
            End If
        Next i
        If Not rng Is Nothing Then rng.RowHeight = 7
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Or you might add another test
VBA Code:
If WorksheetFunction.CountA(rows(i)) = 0 and Not (rows(i).EntireRow.Hidden) Then
 
Last edited:
Upvote 0
Solution
aah, i couldnt help but focus too much on trying to somehow specify those SpecialCells.

perfect, thanks^^
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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