If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Macro Help- Insert row of dashes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-25-07, 10:51
JamesRI JamesRI is offline
Registered User
 
Join Date: Sep 2007
Posts: 2
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
Reply With Quote
  #2 (permalink)  
Old 09-26-07, 09:44
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
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
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 09-26-07, 09:46
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
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
Twitter | Blog
Reply With Quote
  #4 (permalink)  
Old 09-26-07, 10:09
JamesRI JamesRI is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 09-26-07, 10:16
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Think about it and then answer this question;
How do you define the width of a cell?
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On