how to keep from exiting sub with this code?

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
299
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
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,903
Office Version
365
Platform
Windows
Do you have any code between those two snippets?
 

Watch MrExcel Video

Forum statistics

Threads
1,102,781
Messages
5,488,847
Members
407,658
Latest member
Arias610

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top