Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel format ?? 2

Status
Not open for further replies.

gophertee

Programmer
Oct 11, 2000
27
US
I have several hundered rows and columns in Excel. What I want to do is every 4th line Bold and thereafter italics. Hence row 4=bold, row 8=italic, row 12=bold, row 16=italic, row 20=bold, etc.... Help?
 
Hi,
This reply assumes that you have contiguous data in you table.
Code:
Sub FormatRows()
    Dim lRow As Long
    For lRow = 4 To Cells(1, 1).CurrentRegion.Rows.Count Step 4
        If lRow / 8 = Int(lRow / 8) Then
            Rows(lRow).Font.Bold = False
            Rows(lRow).Font.Italic = True
        Else
            Rows(lRow).Font.Bold = True
            Rows(lRow).Font.Italic = False
        End If
    Next
End Sub
Skip,
metzgsk@voughtaircraft.com
 
gophertee,

Having written this, I thought I should still post it - to provide another example of VBA code to achieve your objective.

Thanks also to Skip for his example - it's worth a STAR.

Here's my code...

Dim lastrow As Double

Sub Macro10()
ActiveCell.SpecialCells(xlLastCell).Select
lastrow = ActiveCell.Row
Range("A4").Select
Do Until ActiveCell.Row >= lastrow
ActiveCell.EntireRow.Select
Selection.Font.Bold = True
ActiveCell.Offset(4, 0).Select
ActiveCell.EntireRow.Select
Selection.Font.Italic = True
ActiveCell.Offset(4, 0).Select
Loop
End Sub


Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Here's a non-macro solution:
Make row 4 bold and row 8 italic
Highlight rows 1 thru 8
Click on the Format Painter button (it's the paint brush next to the paste button)
Highlight starting from row 9 to the end of you rows to "paint the format" into those rows.
Mike

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top