Excelbuddy_7
New Member
- Joined
- Nov 6, 2015
- Messages
- 26
Hi
I have a table with 11 columns. I had to use merged cells in the table. Now I want to be able to auto-adjust the cell height (row height), with excel taking into account all the columns and set the cell height.
REQUIRED: Can excel take into account the data in the row, and auto adjust the cell height. It only needs to check the C, V, AP and CE columns in the pic (example table; columns alphabets are far apart because of merged cells). The columns in red are a dropdown list (for info).
CURRENT SITUATION: At the moment I have a code, which checks the cells required, but only in the particular order in the code. For example, first it checks C13, then it checks V13. (default cell height is so 1 line of text can be visible). Now when data in C13 is more than one line, it doesn't change the cell height because V13 (which has no data typed in yet) is only 1 line high (and it checks V13 after C13).
The first bit of code is from "http://www.mrexcel.com/forum/excel-questions/900007-replace-text-selected-drop-down-list-number-same-cell.html". (It is so the data from my drop down lists can be converted to just a number for future use).
The second bit of code (for adjusting cell height), was from another website.
Also at the moment, the first bit of code takes a long time to work as it is also adjusting the cell height after sorting out my dropdown lists. Is there any way to change this?
Another issue at the moment: In my array in the second code (C12, C13, V13, C11), for some reason the code doesn't work for the cell in the first position in the array (in this case C12).
Sorry if it is a bit confusing; hope it all makes sense. Please let me know if you need any more information.
Thanks for any help.
I have a table with 11 columns. I had to use merged cells in the table. Now I want to be able to auto-adjust the cell height (row height), with excel taking into account all the columns and set the cell height.

REQUIRED: Can excel take into account the data in the row, and auto adjust the cell height. It only needs to check the C, V, AP and CE columns in the pic (example table; columns alphabets are far apart because of merged cells). The columns in red are a dropdown list (for info).
CURRENT SITUATION: At the moment I have a code, which checks the cells required, but only in the particular order in the code. For example, first it checks C13, then it checks V13. (default cell height is so 1 line of text can be visible). Now when data in C13 is more than one line, it doesn't change the cell height because V13 (which has no data typed in yet) is only 1 line high (and it checks V13 after C13).
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rChanged As Range, c As Range
'Set a range equal to all the changed cells in the range (there could be more than one at a time)
Set rChanged = Intersect(Target, Range("BD11:BP34"))
'If something did change in the range then
If Not rChanged Is Nothing Then
'Disable events so when/if we change acell on the sheet this whole code doesn't get called again
Application.EnableEvents = False
'Work through each of the column D changed cells
For Each c In rChanged
'Add a "-" at the end of the cell value then split that result into bits by dividing it up at each "-"
'This creates an array of 'bits', the first of which is referenced by zero (0)
'Take that first 'bit', trim off any leading/trailing spaces & put that value in the cell
c.Value = Trim(Split(c.Value & "-", "-")(0))
'Repeat for other changed cells in the column
Next c
'Re-enable events ready for the next change to the worksheet
Application.EnableEvents = True
End If
Dim mw As Single
Dim cM As Range
Dim rng As Range
Dim cw As Double
Dim rwht As Double
Dim ar As Variant
Dim i As Integer
Application.ScreenUpdating = False
'Cell Ranges below, change to suit.
ar = Array("C12", "C13", "V13", "C11")
For i = 1 To UBound(ar)
On Error Resume Next
Set rng = Range(Range(ar(i)).MergeArea.Address)
With rng
.MergeCells = False
cw = .Cells(1).ColumnWidth
mw = 0
For Each cM In rng
cM.WrapText = True
mw = cM.ColumnWidth + mw
Next
mw = mw + rng.Cells.Count * 0.66
.Cells(1).ColumnWidth = mw
.EntireRow.AutoFit
rwht = .RowHeight
.Cells(1).ColumnWidth = cw
.MergeCells = True
.RowHeight = rwht
End With
Next i
Application.ScreenUpdating = True
End Sub
The first bit of code is from "http://www.mrexcel.com/forum/excel-questions/900007-replace-text-selected-drop-down-list-number-same-cell.html". (It is so the data from my drop down lists can be converted to just a number for future use).
The second bit of code (for adjusting cell height), was from another website.
Also at the moment, the first bit of code takes a long time to work as it is also adjusting the cell height after sorting out my dropdown lists. Is there any way to change this?
Another issue at the moment: In my array in the second code (C12, C13, V13, C11), for some reason the code doesn't work for the cell in the first position in the array (in this case C12).
Sorry if it is a bit confusing; hope it all makes sense. Please let me know if you need any more information.
Thanks for any help.