+ Reply to Thread
Results 1 to 7 of 7

Apply macro to all sheets

  1. #1
    Registered User
    Join Date
    06-21-2011
    Location
    England
    MS-Off Ver
    2013
    Posts
    48

    Apply macro to all sheets

    Hello,

    I have a macro that works for the active sheet but I want to make it work for all the sheets of the file.
    the file is as follows:

    Sub DeleteDashRows()

    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual

    Dim SearchCriteria As String: SearchCriteria = "DIV"

    ActiveSheet.Range("A1").Activate
    On Error GoTo FoundAll
    Dim CriteriaRow As Long
    CriteriaRow = Cells.Find(What:=SearchCriteria, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Row

    While CriteriaRow > 0
    ActiveSheet.Rows(CriteriaRow & ":" & CriteriaRow).Delete shift:=xlUp
    On Error GoTo FoundAll
    CriteriaRow = Cells.Find(What:=SearchCriteria, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Row
    Wend
    GoTo FoundAll

    FoundAll:
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Exit Sub

    End Sub
    Many thanks in advance,

    Costas
    Last edited by Costasg; 08-03-2011 at 01:06 PM.

  2. #2
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Apply macro to all sheets

    May be this way. I have not tried this but.
    Please Login or Register  to view this content.
    Last edited by johnjohns; 08-01-2011 at 06:14 AM.
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

  3. #3
    Registered User
    Join Date
    06-21-2011
    Location
    England
    MS-Off Ver
    2013
    Posts
    48

    Re: Apply macro to all sheets

    Hi Johnjohns,

    I tried it but it didn't work. It worked only for the first sheet. I am attaching a sample file to see.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    06-21-2011
    Location
    England
    MS-Off Ver
    2013
    Posts
    48

    Re: Apply macro to all sheets

    Any suggestions?

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Apply macro to all sheets

    Hi Costasg
    This code is a different approach. If you like it use it...if not lose it.
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Registered User
    Join Date
    06-21-2011
    Location
    England
    MS-Off Ver
    2013
    Posts
    48

    Re: Apply macro to all sheets

    Many Thanks jaslake

    It worked great!

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Apply macro to all sheets

    Hi Costasg

    You're welcome...glad I could help.

+ 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