+ Reply to Thread
Results 1 to 14 of 14

Macro to delete entire row based on cell contents

  1. #1
    Registered User
    Join Date
    10-05-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    3

    Macro to delete entire row based on cell contents

    Can any one help writing a macro to delete the row if part # starts with 800- & 550 the #'s are in column A
    Last edited by ATX; 10-05-2011 at 03:48 PM.

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Macro Help

    Please revise your post title to something more specific like macro to delete entire row based on cell contents so that you're not in violation of forum rule #1. I'll post code as soon as it's amended.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

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

    Re: Macro Help

    que? if part # starts with 800? do you think you could provide an example sheet?

  4. #4
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Macro to delete entire row based on cell contents

    Hi GeneralDisarray - I have a code solution I can provide, but can't do so just yet. The forum moderators would rightly crack down on this since this post's title is too ambiguous.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro to delete entire row based on cell contents

    Good now, TL.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Macro to delete entire row based on cell contents

    Assuming you mean that the first ten characters of the cells in the A column need to be tested for the characters 800- & 550:
    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

    Unhappy Re: Macro to delete entire row based on cell contents

    sorry, had it open for a moment before replying....just didn't see your reply

  8. #8
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Macro to delete entire row based on cell contents

    No worries - just means you're anxious to help, which is a good sign.

  9. #9
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to delete entire row based on cell contents

    hi, ATX, option without looping, click "Start"
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    10-05-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macro to delete entire row based on cell contents

    Thanks Guys for the quick response but i am Not sure if i have this set up right i run the macro and no part are deleted

    Sub Export()
    '
    ' Export Macro
    ' Export
    '

    '
    Range("A:B,D:G,J:O,R:W").Select
    Range("R1").Activate
    Selection.Delete Shift:=xlToLeft
    Columns("B:B").Select
    Selection.Cut
    Columns("D:D").Select
    Selection.Insert Shift:=xlToRight
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A2").Select
    End Sub

    Sub DeleteRow()
    Dim lngLastRow As Long
    lngLastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
    For Each c In Range("A1:A" & lngLastRow)
    If Left(c.Value, 10) = "800- & 550" Then c.EntireRow.Delete
    Next
    End Sub
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to delete entire row based on cell contents

    please check attachment, run code "test"

    PS. Any posted code must be enclosed in code tags
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    10-05-2011
    Location
    Texas
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macro to delete entire row based on cell contents

    Thanks watersev that worked question would i be able to add more part to delete in this code
    .AutoFilter 1, "800-*", xlOr, "550*"

  13. #13
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Re: Macro to delete entire row based on cell contents

    Hi ATX

    Hope this code helps you just paste values in the highlighted yellow color.
    If ((ActiveCell.Value() = "0")) Then

    Please Login or Register  to view this content.
    Thanks
    farrukh

  14. #14
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to delete entire row based on cell contents

    hi, ATX, as an option it can be done this way with the help of Autofilter, instead of A,B,C,D,F... you can put other conditions or delete them if not required
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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