Macro to adjust row height based on criteria

ashleym81

New Member
Joined
Dec 12, 2017
Messages
14
Hi,

I have not been able to find the right macro to do what I need. I have conditional formatting on my pages that make a divider line when a "-" is entered into column A. I would like to see if there is something that will adjust the row height to either 8.25cm or 11 pixels when that is entered in. I have a header on line 1 of all tabs, so it would just have to be A2 and on.

If it is something that could be automated based on the criteria (instead of having to run the macro each time) then that would be ideal.

Thank you.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.column > 1 Then Exit Sub
   If Target.Value = "-" Then
      Target.RowHeight = 8.25
   ElseIf Target.Value = "" Then
      Target.EntireRow.AutoFit
   End If
End Sub
this needs to go in the sheet module.
Right click the sheet tab > view code > & paste the above in the code window.

PS You cannot have more than one Worksheet_Change event per sheet.
If you already have a Worksheet_Change event please post the code here.
 
Upvote 0
That is exactly what I needed. Thank you so much for the help!

How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.column > 1 Then Exit Sub
   If Target.Value = "-" Then
      Target.RowHeight = 8.25
   ElseIf Target.Value = "" Then
      Target.EntireRow.AutoFit
   End If
End Sub
this needs to go in the sheet module.
Right click the sheet tab > view code > & paste the above in the code window.

PS You cannot have more than one Worksheet_Change event per sheet.
If you already have a Worksheet_Change event please post the code here.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

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