If then row height set macro

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
338
Office Version
  1. 365
Platform
  1. Windows
Hello,
I need for the cells that have content in column A if not duplicate value of the cell in column A to have row height of 30.

a111
a111
a111
a114
a115
a116
a117
a118
a119
a119
a118
a118
a118
a123
a124
a125
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hello,
I need for the cells that have content in column A if not duplicate value of the cell in column A to have row height of 30.

a111
a111
a111
a114
a115
a116
a117
a118
a119
a119
a118
a118
a118
a123
a124
a125

This will change the row height to 30 for unique entries.

Test it on a copy of the data where the sheet is the active sheet.

VBA Code:
Public Sub subSetRowheight()
Dim arr() As Variant
Dim i As Integer

  arr = Evaluate("UNIQUE(A:A,FALSE,TRUE)")
  
  For i = LBound(arr) To UBound(arr)
    Range("A" & Range("A:A").Find(what:=arr(i, 1)).Row).EntireRow.RowHeight = 30
  Next i
  
End Sub
 
Upvote 1
I get this

1733253742906.png

if I remove the header
1733253804695.png
 
Upvote 0
Upvote 0
Or this WITH the header.

VBA Code:
Public Sub subSetRowheight()
Dim arr() As Variant
Dim i As Integer
Dim rng As Range
  
  Set rng = Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)

  arr = Evaluate("UNIQUE(FILTER(" & rng.Address & "," & rng.Address & "<>""""),FALSE,TRUE)")
  
  For i = LBound(arr) To UBound(arr)
    Range("A" & Range("A:A").Find(what:=arr(i, 1)).Row).EntireRow.RowHeight = 30
  Next i
  
End Sub
 
Upvote 0
Or this WITH the header.

VBA Code:
Public Sub subSetRowheight()
Dim arr() As Variant
Dim i As Integer
Dim rng As Range
 
  Set rng = Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)

  arr = Evaluate("UNIQUE(FILTER(" & rng.Address & "," & rng.Address & "<>""""),FALSE,TRUE)")
 
  For i = LBound(arr) To UBound(arr)
    Range("A" & Range("A:A").Find(what:=arr(i, 1)).Row).EntireRow.RowHeight = 30
  Next i
 
End Sub
with the Header is the wanted result
Thank you
 
Upvote 0
One question
Since is a long macro I have duplicates of dim i as ...
can I edit that to another letter ad dim S ?
 
Upvote 0
Here another macro for you to consider:

VBA Code:
Sub headerHeight()
  Dim ar As Range
 
  For Each ar In Range("A2", Range("A" & Rows.Count).End(3)).SpecialCells(xlCellTypeConstants).Areas
    ar.Cells(1).RowHeight = 30
  Next
End Sub
 
Upvote 1

Forum statistics

Threads
1,224,862
Messages
6,181,466
Members
453,045
Latest member
Abraxas_X

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