+ Reply to Thread
Results 1 to 6 of 6

Run the following macro on all worksheets but sheet1

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2013
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Run the following macro on all worksheets but sheet1

    Hi All,

    I'm new to programming. I am trying to run the following macro on all worksheets except sheet1.

    Sub Rowdelete()
     Dim LR As Long, i As Long
    LR = Range("A" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
       If (Range("E" & i) = "0" And Range("G" & i) = "0" And Range("I" & i) = "0") Then Rows(i).Delete
    Next i
    End Sub

    Any help would be appreciated!!!
    Last edited by dms2228; 07-30-2013 at 01:38 PM.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Run the following macro on all worksheets but sheet1

    You can try this one on a copy of your sheet (untested).

    Please reply.

    Sub Rowdelete()
     Dim LR As Long, i As Long
    
    For Each Sh In Sheets
            With Sh
                If .Name <> "sheet1" Then
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
     For i = LR To 1 Step -1
     If (Range("E" & i) = "0" And Range("G" & i) = "0" And Range("I" & i) = "0") Then Rows(i).Delete
     Next i
    
    End  if
    
    End with
     End Sub
    Last edited by oeldere; 07-30-2013 at 01:16 PM. Reason: End with added in the code
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Run the following macro on all worksheets but sheet1

    Hi, dms2228,

    please add code tags to the procedure.

    Sub Rowdelete()
    Dim LR As Long, i As Long
    If ActiveSheet.Name <> "Sheet1" Then
      LR = Range("A" & Rows.Count).End(xlUp).row
      For i = LR To 1 Step -1
        If (Range("E" & i) = "0" And Range("G" & i) = "0" And Range("I" & i) = "0") Then Rows(i).Delete
      Next i
    End If
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run the following macro on all worksheets but sheet1

    Please use code tags as per forum's rule.

    Sub Rowdelete()
     Dim LR As Long, i As Long
     For Each ws In ThisWorkbook.Worksheets
        With ws
            If .Name <> "Sheet1" Then
               LR = .Range("A" & .Rows.Count).End(xlUp).Row
                For i = LR To 1 Step -1
                   If (.Range("E" & i) = "0" And .Range("G" & i) = "0" And .Range("I" & i) = "0") Then .Rows(i).Delete
                Next i
            End If
        End With
      Next ws
     End Sub

  5. #5
    Registered User
    Join Date
    07-30-2013
    Location
    NYC
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Run the following macro on all worksheets but sheet1

    Thanks everyone. Sorry for the code tag mishap!

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Run the following macro on all worksheets but sheet1

    Oeldere,
    Funny! I did not see your code when I pasted mine. There must be some echo on this site.

+ 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. merge book1,sheet1,book2,sheet1,book3,sheet1 ect
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 01:30 PM
  2. [SOLVED] Take Data From Column on Sheet1 and Insert Into Next Blank Row on Sheet2 Then Clear Sheet1
    By abutler911 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2013, 06:30 PM
  3. Replies: 3
    Last Post: 06-06-2012, 05:36 AM
  4. copying bold data from sheet1 to create new worksheets and rename the worksheet
    By ramdzan in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 03-03-2011, 11:33 AM
  5. Replies: 3
    Last Post: 07-20-2006, 11:30 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