+ Reply to Thread
Results 1 to 9 of 9

Add a row and delete a row by searching a specific text with VBA

  1. #1
    Forum Contributor
    Join Date
    05-10-2016
    Location
    EUROPE
    MS-Off Ver
    Excel 365 64 bitt
    Posts
    194

    Add a row and delete a row by searching a specific text with VBA

    Hi,

    I am trying to make a VBA code that do this macro:

    - Search for value 1 in column A and insert a row to that specific row (Selection.Insert Shift:=xlDown)

    After this macro I need also a macro that:

    - Search for value -1 in column A and delete one row before (like if the value -1 in row A is on the row 33 i would like to delete a row 32)
    but if the row contains anything (numbers or text I mean any value) then Msg would pop up "Cant delete row, row contains value"

    Thanks in advance:
    B.
    Last edited by besis; 01-26-2018 at 07:03 AM.

  2. #2
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: Add a row and delete a row by searching a specific text with VBA

    Hi, besis.

    If you find the target row and Target.Insert Shift:=xlDown inserts a blank row before the target row.
    So deleting one row before the target row ends up with deleting the row you've just inserted.
    Do I make sense?

  3. #3
    Forum Contributor
    Join Date
    05-10-2016
    Location
    EUROPE
    MS-Off Ver
    Excel 365 64 bitt
    Posts
    194

    Re: Add a row and delete a row by searching a specific text with VBA

    Yes, that is true. My mistake. I edited my post. At the macro for deleting has search criteria -1.

  4. #4
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: Add a row and delete a row by searching a specific text with VBA

    Do you have multiple rows that contain value 1 or -1 in column A?

  5. #5
    Forum Contributor
    Join Date
    05-10-2016
    Location
    EUROPE
    MS-Off Ver
    Excel 365 64 bitt
    Posts
    194

    Re: Add a row and delete a row by searching a specific text with VBA

    Hi,

    Yes I have multiple rows that contain value 1 or -1 in column A. I was thinking maybe is good idea for the macro for deleting to put the value -1 on column B.

    Thanks again:
    B

  6. #6
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: Add a row and delete a row by searching a specific text with VBA

    I'm not sure this is what you want, but try it anyway.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    05-10-2016
    Location
    EUROPE
    MS-Off Ver
    Excel 365 64 bitt
    Posts
    194

    Re: Add a row and delete a row by searching a specific text with VBA

    Hi,

    I edited this post in my last thread.

    I tried the code you send, and now it works.
    Thanks a lot for your help,
    B.
    Last edited by besis; 01-28-2018 at 01:46 PM.

  8. #8
    Forum Contributor
    Join Date
    05-10-2016
    Location
    EUROPE
    MS-Off Ver
    Excel 365 64 bitt
    Posts
    194

    Re: Add a row and delete a row by searching a specific text with VBA

    Hi Yujin,

    Your code worked perfectly after I separate your code. For the value 1 for the column A, and the value -1 for column B.
    Searching for 1 and -1 in A:A column didn´t work.

    Thank you very much for your help.
    All the best.
    B.

  9. #9
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: Add a row and delete a row by searching a specific text with VBA

    I'm happy to have been able to help you out

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Searching for Specific Text only
    By Grimace in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 01-09-2017, 09:50 PM
  2. Searching Specific Cells for Specific Text
    By sebbie99 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-21-2014, 02:53 PM
  3. [SOLVED] Searching a Range for a Specific Text and put a different text in a different cell
    By AngelAzrael in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-14-2013, 09:25 AM
  4. Replies: 19
    Last Post: 04-10-2013, 08:30 AM
  5. Searching for specific word then delete it
    By karinos57 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2008, 04:20 PM
  6. Searching for Specific Text in a Row
    By NewExcelUser in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-06-2007, 10:22 PM
  7. searching for specific text
    By clerk in forum Excel General
    Replies: 1
    Last Post: 12-06-2005, 08:20 PM

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