+ Reply to Thread
Results 1 to 5 of 5

Macros that deletes row and everything under it for all sheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Macros that deletes row and everything under it for all sheets

    Hi I have a workbook, with worksheets that have the word "Summary public" which appears once in Column A. I am trying to create a macros that searches for this exact word in all sheets, and deletes the row the word is in and all rows underneath it, for this purpose 1000 rows is sufficient.
    Last edited by undergraduate; 01-11-2011 at 12:13 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macros that deletes row and everything under it for all sheets

    Try this:
    Option Explicit
    
    Sub DeleteSummaryPublicRows()
    Dim ws As Worksheet
    Dim SumPubFIND As Range
    
    On Error Resume Next
    
        For Each ws In Worksheets
            Set SumPubFIND = Range("A:A").Find("Summary Public", _
                LookIn:=xlValues, LookAt:=xlWhole)
            If Not SumPubFIND Is Nothing Then
                Range(SumPubFIND, ws.Range("A" & Rows.Count) _
                    .End(xlUp)).EntireRow.Delete xlShiftUp
                Set SumPubFIND = Nothing
            End If
        Next ws
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Macros that deletes row and everything under it for all sheets

    Thank you very much for this.
    Unfortunately it only works for one worksheet, i.e. if I run the macros directly on the worksheet. It does not work/ run for all worksheets in the workbook for some reason.
    I would have to manually run it on each worksheet. Is there an issue with the For loop?
    Thank you again.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,330

    Re: Macros that deletes row and everything under it for all sheets

    Hi undergraduate,

    Do you have extra spaces before, in the middle or after "Summary public" in any of the cells? It would need to be what is in the code EXACTLY.
    In the code "Summary public" is not equal to "Summary public " because of the extra space in the second.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Re: Macros that deletes row and everything under it for all sheets

    Thank You, simple enough and helped me resolve my issue. Thanks to both of you!

+ 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