Excel row height (Conditional formatting?)

I have a spreadsheet where every other row is a different height and I would like to know if there is a way to set it up so I don't have to set each row individually. There are only two row heights, 12.75 and 4 and they alternate.


snap01001.jpg
timamartinAsked:
Who is Participating?
 
Rory ArchibaldCommented:
You can't do it with conditional formatting but you can do it with a macro, such as this (select your data first):
 

Sub FormatRowHeights()
   Dim rngRow As Range
   For Each rngRow In Selection.Rows
      If rngRow.Row Mod 2 = 0 Then
         rngRow.RowHeight = 4
      Else
         rngRow.RowHeight = 12.75
      End If
   Next rngRow
End Sub

Open in new window

0
 
Saurabh Singh TeotiaCommented:
Assuming you want to start from row-1 till the 100 row you can use the following code it will do what you are looking for, Formating the row-1 to 12.75 and next to 4 and so on till row-100
Saurabh...

Sub rowheight()
Application.ScreenUpdating = False
 
    Dim i As Long
    i = 1 ' Your starting row
    For i = 1 To 100
        If Application.Evaluate("mod(" & i & ",2)") = 1 Then
            Rows(i).rowheight = 12.75
        Else
            Rows(i).rowheight = 4
        End If
    Next i
 
 
Application.ScreenUpdating = True
End Sub

Open in new window

0
 
timamartinAuthor Commented:
Ok...now I am going to show my novice ability - where do I insert/use the coding shown above?
0
 
Rory ArchibaldCommented:
If you press Alt+f11 to open the VBEditor, then choose Insert-Module from the menu and paste that code into the window that appears. You can then run the macro in Excel by pressing f8 and selecting it from the dialog, assuming your macro security is not set to high in the Trust Center (under Excel Options).
0
 
Saurabh Singh TeotiaCommented:
One small correction in rory comment, to run the macro you need to press alt+f8 on your which will open the macro window, showing the macro which you just inserted, Just select the same and hit run which will run the macro and do what you are looking for.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.