Results 1 to 2 of 2

Thread: how to keep from exiting sub with this code?
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Dec 2016
    Location
    Houston, TX
    Posts
    246
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question how to keep from exiting sub with this code?

    Code:
    For Each nP In Range(Cells(1, 14), Cells(cntRowsN, 14))
    
    ' E-H-S INCIDENT TALLY
    ' COPY THE ROWS IN THE "EHS" COLUMN (ON THE ANALYTICS SHEET) AND PASTE ONTO THE TOTAL COLUMN (A2) ON THE "REPORTS" WORKSHEET:
    
        If cntRowsN >= 1 Then
        'copies just the rows in column F and pastes them on the REPORTS worksheet starting with cell A2.
        ActiveWorkbook.Worksheets("ANALYTICS").Activate
        ActiveWorkbook.Worksheets("ANALYTICS").Range(Cells(1, 14), Cells(15, 14)).Select
        Selection.Copy
        ActiveWorkbook.Worksheets("REPORTS").Activate
        ActiveWorkbook.Worksheets("REPORTS").Range("J2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveWorkbook.Worksheets("ANALYTICS").Activate
    
        Exit For
        End If
    Next
    The problem I am having is that if 'cntRowsN' is 0, then it exits the entire sub...
    but what I need it to do is if cntRowsN is zero just to exit this one procedure and go on to the next event (which is just like the above code but for another variable )

    here is the next bit of code that follows the code posted above...(and there are 4 other ones just like this one that it needs to run through but its skipping all of them and just exiting the entire sub)

    Code:
    For Each lP In Range(Cells(1, 12), Cells(cntRowsL, 12))
    
    ' INTERNAL SEATEX INCIDENT TALLY
    ' COPY THE ROWS IN THE "SEATEX INTERNAL" COLUMN (ON THE ANALYTICS SHEET) AND PASTE ONTO THE TOTAL COLUMN (H2) ON THE "REPORTS" WORKSHEET:
    
        If cntRowsL >= 1 Then
        'copies just the rows in column F and pastes them on the REPORTS worksheet starting with cell H2.
        ActiveWorkbook.Worksheets("ANALYTICS").Activate
        ActiveWorkbook.Worksheets("ANALYTICS").Range(Cells(1, 12), Cells(15, 12)).Select
        Selection.Copy
        ActiveWorkbook.Worksheets("REPORTS").Activate
        ActiveWorkbook.Worksheets("REPORTS").Range("H2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        ActiveWorkbook.Worksheets("ANALYTICS").Activate
    
        Exit For
        End If
    Next

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,298
    Post Thanks / Like
    Mentioned
    471 Post(s)
    Tagged
    47 Thread(s)

    Default Re: how to keep from exiting sub with this code?

    Do you have any code between those two snippets?
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •