VBA - Add new row based on value and copy adjecent row and paste in the new row

  • Hello


    I am trying to get a code to work.


    I want to first search for a value in the A column.
    If that value is found in any cell.
    Create a new row above and copy the row above and paste it into the new row.


    So for example.
    COLUMN A
    row1:data
    row2:data
    row3:data
    row4:keyword
    row5:data
    row6:data



    code searches for the word "keyword"
    when found a new row is created above keyword (so row 4 becomes row 5)
    then copy the data in the row above the newly created row
    and paste that data into the newly created row
    then clear the newly created row from all data except formulas and formats, so the row is empty but contain formulas and format edits.


    have tried several codes and i get a row to be created after searching for the "keyword"
    but then im stuck.

  • Re: VBA - Add new row based on value and copy adjecent row and paste in the new row


    Hello Behedwin,


    Try out the code below. Bare in mind you will need to change the "Keyword" and sheetname with these two lines:

    Code
    Keyword = "Keyword"With Worksheets("Sheet1").Columns("A:A")


    which appear in the full code below



    This assumes there is only 1 instance of the keyword in column A. However, it can be adapted to find multiple instances.


    Let me know if it works.
    Thanks
    Caleeco

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!