+ Reply to Thread
Results 1 to 5 of 5

Use VBA loops to search for a list of values, delete columns they are found in

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    MA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Use VBA loops to search for a list of values, delete columns they are found in

    I've been working on an excel sheet where I am using a macro to basically run a 'Find Function' to find a word/phrase on a separate sheet and then delete the entire column that this word/phrase is located in. Currently, I have this:

    Please Login or Register  to view this content.
    This works perfectly to reference Cell C53 (which is where the word/phrase is inputted by a user) and then go to the 'Forecast' sheet and delete the columns the word/phrase is located in along with the subsequent columns to the right until the next populated column. However, I need it to do 2 more things.
    a. Currently it only finds the word once- basically it "finds next" instead of "find all". I was thinking making a loop so that once it finds one and deletes the column, it finds the same word again and deletes that column (and the subsequent empty rows next to it) until the word is no longer on the sheet at all.
    b. Secondly, I need it to find more than one word/phrase. Right now it references cell 'C53' but I need it to then go on to 'C54' and do the same thing, then 'C55', then 'C56', etc. etc. UNTIL it reaches a cell that simply has a '0' in it.

    Any help with this 'Loop Inception' problem would be greatly appreciated! I am very new to VBA and I was just given the task of doing this

    Thanks!

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Use VBA loops to search for a list of values, delete columns they are found in

    Where can the searchtext be found ? in 1 row or several rows ?

    Please Login or Register  to view this content.
    Last edited by snb; 07-24-2013 at 04:50 PM.



  3. #3
    Registered User
    Join Date
    07-24-2013
    Location
    MA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Use VBA loops to search for a list of values, delete columns they are found in

    The search text is currently found in one row (actually just one cell, C53), but I need it to be found in multiple rows (C54, C55, etc.)

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Use VBA loops to search for a list of values, delete columns they are found in

    Always in column C ?

  5. #5
    Registered User
    Join Date
    07-24-2013
    Location
    MA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Use VBA loops to search for a list of values, delete columns they are found in

    Yeah, the search criteria will always be in column C.

+ 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. Fast way to delete row if value is not found in a list
    By Seraph122 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-28-2013, 12:45 AM
  2. VB A to loop to search through a list and delete a record if found
    By 4am in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2011, 10:26 AM
  3. search a cell for values in a range, return values found
    By carpe.cervisiam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2011, 12:52 PM
  4. Search cell (external book) and delete row if found
    By Zaeguzah in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-22-2009, 03:47 AM
  5. Search column bottom up then delete rows based on value found
    By jaslake in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-08-2009, 10:24 AM

Tags for this Thread

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