+ Reply to Thread
Results 1 to 9 of 9

code to clear all contents in columns with specific text in row 2

  1. #1
    Registered User
    Join Date
    08-24-2012
    Location
    Columbus
    MS-Off Ver
    Excel 2010
    Posts
    46

    code to clear all contents in columns with specific text in row 2

    Below is my initial code that can't get past the first line.

    Please Login or Register  to view this content.
    Any help would be greatly appreciated.

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: code to clear all contents in columns with specific text in row 2

    what exactly are you trying to do?
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    08-24-2012
    Location
    Columbus
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: code to clear all contents in columns with specific text in row 2

    I'm trying to clear the contents of all data in each column that has the text conaining "D_MA" in that columns row 2. For instance, if cell F2 has 30D_MA, I want the macro to clear all contents in Column "F" -- but to do this for all columns that contain "D_MA" in row 2.

  4. #4
    Registered User
    Join Date
    07-09-2014
    Location
    Montreal, Quebec
    MS-Off Ver
    07
    Posts
    15

    Re: code to clear all contents in columns with specific text in row 2

    if right(cells(2,i),4) = "D_MA" then ..... ?

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: code to clear all contents in columns with specific text in row 2

    Oh ok, that's sorta what it looked like but was hard to tell.

    On it!

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: code to clear all contents in columns with specific text in row 2

    Please Login or Register  to view this content.

  7. #7
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: code to clear all contents in columns with specific text in row 2

    That will do it. Run this while the sheet you would like to operate on is the active sheet. Save both the Sub and the Function to a module, and run the sub.
    The macro will prompt you for the "text to obliterate" - just enter "D_MA" and press enter.


    It will then look on the 2nd row for anything containing D_MA (partial match, so D_MA just needs to be part of the text) and clearContents on the entire column. :D

  8. #8
    Registered User
    Join Date
    08-24-2012
    Location
    Columbus
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: code to clear all contents in columns with specific text in row 2

    Quote Originally Posted by GeneralDisarray View Post
    That will do it. Run this while the sheet you would like to operate on is the active sheet. Save both the Sub and the Function to a module, and run the sub.
    The macro will prompt you for the "text to obliterate" - just enter "D_MA" and press enter.


    It will then look on the 2nd row for anything containing D_MA (partial match, so D_MA just needs to be part of the text) and clearContents on the entire column. :D
    Thanks a lot GerneralDisarray!

    I did modify it just a bit (the text I'm searching for won't change - so I did away with the input box) but it is working perfectly.

  9. #9
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: code to clear all contents in columns with specific text in row 2

    No problem That FindAll function is VERY handy to keep around, you'll use it alot.

    Please mark your thread solved.

    To mark your thread solved do the following:
    New Method
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

    Old Method
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save

+ 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] Clear contents in specific cell and the cells in the next 2 columns to the right
    By JRidge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-04-2014, 01:25 AM
  2. Code to clear contents of a cell based on specific criteria
    By srsev in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-21-2013, 01:38 PM
  3. code that will delete and clear specific contents in the workbook
    By Khanzaki in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2013, 01:18 PM
  4. Code to clear contents of specific cells based upon if key exists in other sheets
    By seputus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2013, 07:25 PM
  5. Replies: 1
    Last Post: 08-22-2006, 12:30 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