how to keep from exiting sub with this code?

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Code:
For Each nP In Range(Cells(1, 14), Cells(cntRowsN, 14))

[COLOR=#008000]' E-H-S INCIDENT TALLY[/COLOR]
[COLOR=#008000]' COPY THE ROWS IN THE "EHS" COLUMN (ON THE ANALYTICS SHEET) AND PASTE ONTO THE TOTAL COLUMN (A2) ON THE "REPORTS" WORKSHEET:[/COLOR]

    If cntRowsN >= 1 Then
   [COLOR=#008000] 'copies just the rows in column F and pastes them on the REPORTS worksheet starting with cell A2.[/COLOR]
    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))

[COLOR=#008000]' INTERNAL SEATEX INCIDENT TALLY[/COLOR]
[COLOR=#008000]' COPY THE ROWS IN THE "SEATEX INTERNAL" COLUMN (ON THE ANALYTICS SHEET) AND PASTE ONTO THE TOTAL COLUMN (H2) ON THE "REPORTS" WORKSHEET:[/COLOR]

    If cntRowsL >= 1 Then
[COLOR=#008000]    'copies just the rows in column F and pastes them on the REPORTS worksheet starting with cell H2.[/COLOR]
    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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Do you have any code between those two snippets?
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top