I have some VBA code which I have in the worksheet code area and I think I am close to getting it to work but not sure what I am doing wrong.
The worksheet in question is never directly edited, but a range of cells D5:D30 pull their data from cells within other sheets (using ='sheet'!H1etc). By the nature of the content these cells are going to fill up quickly so I would like each row to auto-fit height based on the content on column D. Several people will be opening this document and won't know how to do this manually and as I am worried they may miss details that go beyond the size of the cell, I'd like this process to happen automatically whenever any of the content of column D is updated.
The code I have is
Any one able to point out what I might be doing wrong? Do I perhaps need to attached the VBA on to the worksheet I will be editing directly?
Thanks
The worksheet in question is never directly edited, but a range of cells D5:D30 pull their data from cells within other sheets (using ='sheet'!H1etc). By the nature of the content these cells are going to fill up quickly so I would like each row to auto-fit height based on the content on column D. Several people will be opening this document and won't know how to do this manually and as I am worried they may miss details that go beyond the size of the cell, I'd like this process to happen automatically whenever any of the content of column D is updated.
The code I have is
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an Action when they are changed.
Set KeyCells = Range("D5:D30")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Change the height of the header row when one of the defined cdlls is changed
Rows("1:30").EntireRow.AutoFit
End If
End Sub
Any one able to point out what I might be doing wrong? Do I perhaps need to attached the VBA on to the worksheet I will be editing directly?
Thanks