Results 1 to 6 of 6

Macro to Insert copy of Row based on text String

Threaded View

  1. #1
    Registered User
    Join Date
    01-16-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Talking Macro to Insert copy of Row based on text String

    Hi guys
    This is my first post - I hope it goes in correctly...

    I need help to alter data in my spreadsheet but I have no VBA knowledge and I can't find anyone at my employment to help. I hope someone here can assist.


    I would like a macro to check cells in Column "A" to detect the first 8 characters of text as "employee". In some cases the text is EmployeeID or EmployeeNumber, so I need to detect the first 8 characters.
    When a match of the first 8 characters is found insert copy of Row 1 below each instance of the detected text.
    (Actually Row 1 is an empty row except for the data in cell A1. So inserting a blank row and then copying the data from cell A1 into the first cell of the new Row will work too)


    I was trying to alter these snippets of code but I'm lost...
    The Data Begins in Row 5 of Column A

    (first snippet)

    Sub InsertRow_At_Employee()
    
    
           For i = Range("A65536").End(xlUp).Row To 5 Step -1
           If Left(Cells(i, 1).Value, 8) = "employee" Then Rows(i + 1).Insert 
       Next
    
    End Sub
    (second snippet)

    If Left(Cells(i, 1).Value, 8) = "employee" Then
     Cells(A, 1).Copy Destination:=Cells(i+1, 1)
     End If

    I hope you guys can help -
    Thanks,
    Larry

    Moderator's Edit: Use code tags when posting code. To do so in future, select your code and click on the # icon at the top of your ost window.
    Last edited by j2591; 02-04-2013 at 10:30 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1