+ Reply to Thread
Results 1 to 6 of 6

Macro to find a column header and delete certain rows of data

  1. #1
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Question Macro to find a column header and delete certain rows of data

    Hi,


    Can any please advise me of the macro code needed to search a worksheet for a heading in row 1 called ‘Contract Type’ (if it exists) and delete any rows where there is the text ‘Fixed Price’ (if any exists) in any of the cells in that column

    Any assistance would be greatly appreciated

    Many thanks

    Rob

    N.B Excel version 2007
    Rob

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro to find a column header and delete certain rows of data

    Perhaps a macro like this?

    Please Login or Register  to view this content.
    Alf

  3. #3
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Re: Macro to find a column header and delete certain rows of data

    Alf,

    just what the Doctor ordered !! It worked a treat.

    Many thanks indeed

    Regards


    Rob

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro to find a column header and delete certain rows of data

    Glad to be of help. Thanks for feedback and rep!

    Alf

  5. #5
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro to find a column header and delete certain rows of data

    Hi Rob

    I missed the obvious i.e. if no cell in row 1 has the text "Contract Type" then the macro throws an error and stops. Solution to that is to place auto filter settings "inside" the If statement. I'm also not totally happy with the CountA command this assumes every cell in range is not empty. So with all that in mind I've written a more "robust" macro.

    This finds the rightmost column that is not "empty" and checks all columns (row 1) from first to the last column and I've also put the auto filter settings "inside" the If test.

    Please Login or Register  to view this content.
    Sorry about this.

    Alf

  6. #6
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Re: Macro to find a column header and delete certain rows of data

    Alf,

    I've just picked up your updated thread and have amended by code accordingly

    Many thanks Again


    Rob

+ 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. Macro to find word in column then delete contents in specified rows
    By Dleopoldi914 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2013, 10:26 AM
  2. [SOLVED] macro to find same largest values in a column and delete all other rows..help required!!
    By gokzee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2012, 11:34 PM
  3. [SOLVED] VBA Find last row and column that contain data and delete all blank rows and blank columns
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-03-2012, 01:07 PM
  4. Find a value in a column and delete the 10 rows after
    By ExcelJET in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2012, 02:05 PM
  5. Replies: 4
    Last Post: 09-18-2012, 10:54 AM

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