View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
forest8 forest8 is offline
external usenet poster
 
Posts: 41
Default Autowrap in a cell

The first one was

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range

With Target
If .MergeCells And .WrapText Then
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
Application.ScreenUpdating = True
End If
End With
End Sub


The second one was:

In place of the word "password" you would hard code your password and remove
the leading apostrophe assuming it's password protected. Otherwise ignore it.
Minimal testing:-

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range
Dim ProtectStatus As Boolean

With Target
If .MergeCells And .WrapText Then
ProtectStatus = Me.ProtectContents
If ProtectStatus Then Me.Unprotect ' "password"
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
On Error Resume Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
On Error GoTo 0
Application.ScreenUpdating = True
If ProtectStatus Then Me.Protect ' "password"
End If
End With
End Sub

"Pete_UK" wrote:

Well, we are not likely to know the macro that you mention, so please
post it here.

Pete

On Sep 8, 3:08 pm, forest8 wrote:
Hello

I've created an excel database in Excel 2007. Depending on the responses on
the first sheet, different responses appear on the next sheet.

The difficulty lies in the second sheet where it's possible to have more
than 1 response per cell. Conversely. tf there is no response in the first
sheet for a particular cell, then it's left blank in the second sheet.

I would like to get the row height for the second sheet to adjust based on
possible responses. Is this possible?

I'm thinking of a macro that would do the trick but I'm not sure of how it
works. While searching for possible answers in this community, I found a
macro created by Gord Dibben. I got this VBA error and wasn't sure of how to
proceed.

Any advice would be greatly appreciated.