1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: incrementing a line Macro help

Discussion in 'Business Applications' started by ksquared, Jan 29, 2005.

Thread Status:
Not open for further replies.
  1. ksquared

    ksquared Thread Starter

    Joined:
    Apr 19, 2004
    Messages:
    68
    Hi,
    I need to add an empty line between each of the rows I have populated on a spreadsheet (Microsoft Excel 2000)

    Example:
    select line 2, insert row, format the cells on the new line 2.
    select line 4, insert row, format the cells on the new line 4.

    I need to repeat this process for hundreds of rows and don't want to have to do it manually.

    I created a macro to do this but was wondering if someone could help me with a command that would automatically increment to the next even line without me having to write it out as I did below.

    Any help would be much appreciated. A programmer I'm not. Thanks K2


    Rows("2:2").Select
    Selection.Insert Shift:=xlDown
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Rows("4:4").Select
    Selection.Insert Shift:=xlDown
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Rows("6:6").Select
    Selection.Insert Shift:=xlDown
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    etc.
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Click in a cell in the row that you want to start in and run the following macro.

    Code:
    Public Sub InsertRows()
    
    Do Until ActiveCell.Row = Cells(Rows.Count, "A").End(xlUp).Row + 1
    
    Rows(ActiveCell.Row).Insert Shift:=xlDown
    Rows(ActiveCell.Row).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    ActiveCell.Offset(2, 0).Select
    Loop
    
    End Sub
    Rollin
     
  3. ksquared

    ksquared Thread Starter

    Joined:
    Apr 19, 2004
    Messages:
    68
    Perfect!!!! Thank-you Rollin. What would I do without this board....
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/324717

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice