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.
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
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.
 

ashleym81

New Member
Joined
Dec 12, 2017
Messages
14
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,123,321
Messages
5,600,948
Members
414,417
Latest member
Nobu

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
Top