View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Change row height if cell is blank

tom is the expert, so I don't often get to modify his code. I think this is
a better way of doing what you have below. the logic you have to determine
if all the cells in a row are empty is faulty.

the code will work with your range also.

Sub blankline()

'get last cell in column with data
'columns.count is a constant which is the last column number
'xltoleft moves from the last column to left until a CELL IS FOUND
Lastcolumn = Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Column
'A empty row will have lastt column as 1
'Need to make surre column 1 is also empty
If (Lastcolumn = 1) And IsEmpty(Cells(ActiveCell.Row, 1)) Then

ActiveCell.EntireRow.RowHeight = 6

End If


End Sub

"Philip J Smith" wrote:

Hi. I hope some-one can help.

I have hacked together and modified some code posted for other purposes by
dmcritchie (1 posting) and Tom Ogilvy (2 postings). I thought that I
understood what the code was doing, but it doesnt seem to work €“ any error
is mine, not theirs.

In a column of labels with blank rows between elements I want to set the row
height to 6 if the cell is blank, otherwise leave the row height as default.

The code is given below:

'Macro to set row heights
Sub SetHeights()
AutoCalcOff
Dim cell As Range, Rng As Range
Set Rng = Range("B2:B" & Cells.Rows.Count). _
SpecialCells(xlConstants, xlTextValues)
For Each cell In Rng
If Len(Trim(cell.Value)) = 0 Then
cell.EntireRow.RowHeight = 6
End If
Next cell
AutoCalcOn
End Sub

AutoCalcOff and AutocalcOn are calls to other subroutines.

Regards

Phil Smith