?
Solved

Excel row height (Conditional formatting?)

Posted on 2009-04-16
5
Medium Priority
?
740 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:timamartin
  • 2
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 1000 total points
ID: 24157355
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
 
LVL 59

Assisted Solution

by:Saurabh Singh Teotia
Saurabh Singh Teotia earned 1000 total points
ID: 24157379
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
 

Author Comment

by:timamartin
ID: 24157427
Ok...now I am going to show my novice ability - where do I insert/use the coding shown above?
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 24157449
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
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 24157509
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question