VBA - Set row height based on value in cells

Spaztic

New Member
Joined
Jul 27, 2023
Messages
30
Office Version
  1. 365
Platform
  1. Windows
Need help! The code I've tried is too far off to even show.

I'm looking for vba code that would:
  • look at Column B to be NOT blank, AND
  • look at Column C to contain 'X'
  • IF this is true, the entire row height would be set to height = 75
  • However, if row height is already greater than 75, it would leave the row alone (e.g. if someone already expanded the row to 100, it would stay at 100) This is the tricky part, in my opinion.
  • NOTE: This would look through the entire worksheet and expand all rows that met the criteria
Thank you for ANY help you may have for me in advance!

Starts like this:
1704898316563.png


When the code is run, should look like this
1704898637647.png
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this code:
VBA Code:
Sub SetRowHeight()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column C with data
    lr = Cells(Rows.Count, "C").End(xlUp).Row
    
'   Loop through all rows
    For r = 1 To lr
'       See if column B not empty and C is "X"
        If Cells(r, "B") <> "" And Cells(r, "C") = "X" Then
'           See if height of row is < 75
            If Rows(r).RowHeight < 75 Then
'               Set row height to 75
                Rows(r).RowHeight = 75
            End If
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,089
Messages
6,123,058
Members
449,091
Latest member
ikke

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