VBA to adjust Row Height based on Characters

Jasuan

New Member
Joined
Jan 16, 2014
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Through research I understand that there is no formula to adjust row height, so now my question ventures into VBA:

In my workbook employees enter data into Cell B68 of worksheet DATA and that data is populated into merged Cell D8:J9 of worksheet V1. This happens for every "V" worksheet, of which there are 40 (i.e. DATA!B70 for worksheet V2, DATA!B72 for worksheet V3, etc.). The problem I run into is if there is too much text, employees have to unlock the worksheet to adjust it. We would like to avoid that.

Since the data is populated by formula ("=IF(DATA!B68=0," ",DATA!B68)") the wrap text function doesn't work. So my initial thought was to take an adjacent cell and have it use LEN() and use an algorithm formula to adjust height (i.e. add 1/8" height for every 83 characters). Since I can't do this, I will need a VBA to mimic this type of behavior.

I would need to have a minimum height of 3/8".

Is this possible? Is there a man or woman brave enough to take on this problem? I am appreciative of all responses.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You might need to fine tune the math in there to adjust the row height the way you like, but something like this should work.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim l As Integer
Dim RH As Double
l = Len(Range("D8").Value)
RH = (l / 83) * 8
If RH < 20 Then RH = 20
Range("8:9").RowHeight = RH
End Sub
 
Upvote 0
You might need to fine tune the math in there to adjust the row height the way you like, but something like this should work.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim l As Integer
Dim RH As Double
l = Len(Range("D8").Value)
RH = (l / 83) * 8
If RH < 20 Then RH = 20
Range("8:9").RowHeight = RH
End Sub
Thanks for the reply.
I'll input this on Monday and see how she runs. In the VBA I don't see how it references different sheets.
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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