Insert a line in Excel using a Macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cb38
    New Member
    • Apr 2008
    • 1

    Insert a line in Excel using a Macro

    I have an Excel spreadsheet where all data resides in column A.

    Cell A1 is blank and the data follows after that. I need to insert a line after each line with the ChangeType: add. How can I do this with macro?


    dn: CN=
    changetype: add
    title:
    telephoneNumber :
    displayName:
    mail:

    dn: CN=
    changetype: add
    title:
    telephoneNumber :
    displayName:
    mail:
  • if1467
    New Member
    • Feb 2008
    • 25

    #2
    Originally posted by cb38
    I have an Excel spreadsheet where all data resides in column A.

    Cell A1 is blank and the data follows after that. I need to insert a line after each line with the ChangeType: add. How can I do this with macro?


    dn: CN=
    changetype: add
    title:
    telephoneNumber :
    displayName:
    mail:

    dn: CN=
    changetype: add
    title:
    telephoneNumber :
    displayName:
    mail:
    Try this:

    Code:
    Sub Insert_Row()
    
    Dim rownum As Integer
    Dim Currcell As Range
    
    rownum = 4
    Set Currcell = ActiveSheet.Cells(rownum, 1)
    Do While Currcell <> ""
        Currcell.insert Shift:=xlDown
        rownum = rownum + 8
        Set Currcell = ActiveSheet.Cells(rownum, 1)
    Loop
    End Sub

    Comment

    Working...