Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2007
    Posts
    2

    Unanswered: Macro Help- Insert row of dashes

    I already have the following macro to insert a blank row after every 5 rows:
    Instead of blank rows, I would rather an entire row od dashes or dots, so when printed, I have data separated every 5 rows by continuous dashes.

    Sub InsertRows()
    Application.ScreenUpdating = False
    Dim numRows As Integer
    Dim r As Long
    r = Cells(Rows.Count, "A").End(xlUp).Row
    numRows = 1
    For r = r To 1 Step -5
    ActiveSheet.Rows(r + 1).Resize(numRows).Insert
    Next r
    Application.ScreenUpdating = True
    End Sub

    Additionally, is there a way to shade every other group of 5 rows?
    Any help is appreciated.
    James

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Give this a try and let us know how you get on.
    Code:
    For r = r To 1 Step -5
    ActiveSheet.Rows(r + 1).Resize(numRows).Insert
    ActiveSheet.Rows(r + 1).Value = "****TEST****"
    ...
    George
    Home | Blog

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Oh and
    Code:
    Sub ShadeEveryOtherRow() 
        Dim Counter As Integer 
    
        For Counter = 1 To Selection.Rows.Count 
            If Counter Mod 2 = 1 Then 
                Selection.Rows(Counter).Interior.Pattern = <insert colour>
            Else
                Selection.Rows(Counter).Interior.Pattern = <insert other colour>
            End If 
        Next 
         
    End Sub
    George
    Home | Blog

  4. #4
    Join Date
    Sep 2007
    Posts
    2
    They both work well, thanks. Is there a way to make the dashes/dots fill cells of varying widths? In the one you gave above, it only enters the amount of dashes entered in the macro.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Think about it and then answer this question;
    How do you define the width of a cell?
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •