Johnny Thunder
Well-known Member
- Joined
- Apr 9, 2010
- Messages
- 693
- Office Version
- 2016
- Platform
- MacOS
Hi Group,
Working on a script that is doing a copy/paste type function and looping down a list of text to update a report.
I have the code working fine, but when I come across a blank cell I would like the macro to EXIT SUb, the problem that I am having is that I have code after the Exit sub line that calls other macros if a specific cell has text, My question is, how can I rewrite my code so that the Macro REALLY closes out and exits the sub without doing anymore?
I tried the GOTO approach but I obviously didn't know what I was doing because it didn't work.
My code below:
Working on a script that is doing a copy/paste type function and looping down a list of text to update a report.
I have the code working fine, but when I come across a blank cell I would like the macro to EXIT SUb, the problem that I am having is that I have code after the Exit sub line that calls other macros if a specific cell has text, My question is, how can I rewrite my code so that the Macro REALLY closes out and exits the sub without doing anymore?
I tried the GOTO approach but I obviously didn't know what I was doing because it didn't work.
My code below:
Code:
Sub Copy_CCodes()
Dim lastRow As Long
Dim Datastore As Worksheet, FinalDest As Worksheet
Dim i As Range
Set Datastore = Sheets("Lookups2")
Set FinalDest = Sheets("Summary")
lastRow = Datastore.Cells(Rows.Count, "L").End(xlUp).Row
Set rng = Datastore.Range("CCodes")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Call FindRep
Datastore.Activate
Range("N2").Select
'Set Do loop to stop when two consecutive empty cells are reached.
If FinalDest.Range("A9").Value = "" Then
GoTo KillCode
'ActiveCell.Offset(1, 0).Select
Else
'Do Until IsEmpty(ActiveCell) And IsEmpty(ActiveCell.Offset(1, 0))
Do Until IsEmpty(ActiveCell)
ActiveCell.Copy
FinalDest.Range("RPTCC").PasteSpecial Paste:=xlValues
Calculate
Call SaveSheet
' Step down 1 rows from present location.
ActiveCell.Offset(1, 0).Select
Loop
End If
KillCode:
Exit Sub
Call CountFiles
End Sub