Compile Error - label not defined - Previously ran fine

buxx1

New Member
Joined
May 23, 2016
Messages
5
Hi all,

When I run some code in VBA (which previously ran fine) I am getting a 'label not defined' error.

On the debugger screen it suggests it is the 'GoTo' part, however it looks fine (to me).

Here is the top and bottom part of my code:

TOP:
Private Sub UpdateAll_Click()

Dim LastRow As Long
Dim MaxDate As Date

'Go to error handler on error
1 On Error GoTo ErrorRecord

BOTTOM:
Exit Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Error Handler
ErrorRecord:

'Select sheet to dump error
732 Workbooks("Update Databases.xls").Sheets("Errors").Range("A1").EntireRow.Insert

'Log errors
733 Workbooks("Update Databases.xls").Sheets("Errors").Range("A1").Value = "Line: " _
& Erl & ", " & "Error " & Err.Number & ": " & Err.Description

'Resume
734 Resume Next

End Sub


-
Any ideas would be appreciated, thanks.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Am no VBA expert but it looks ok to me. I copied the code and just changed WorkBooks/Sheets to "Sheet1" so it would run against a blank workbook and it worked without error.
 
Upvote 0
Am no VBA expert but it looks ok to me. I copied the code and just changed WorkBooks/Sheets to "Sheet1" so it would run against a blank workbook and it worked without error.

Thank you for looking, I will post more of the code now.
 
Upvote 0
Private Sub UpdateAll_Click()

Dim LastRow As Long
Dim MaxDate As Date

'Go to error handler on error
1 On Error GoTo ErrorRecord

'Clear errors sheet ready for new data
2 Sheets("Errors").Cells.Clear

'Turn off alerts from queries
3 Application.DisplayAlerts = False

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
(Code removed)

End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


Sub shfdohfs()
(Code removed)

731 Exit Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Error Handler
ErrorRecord:



'Resume
734 Resume Next

End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
Upvote 0
You can't jump to a label in a different routine.
 
Upvote 0
Can you give me more of an explanation? Thanks

Code:
Private Sub UpdateAll_Click()

 Dim LastRow As Long
 Dim MaxDate As Date

 'Go to error handler on error
 1 On Error GoTo ErrorRecord


 End Sub



 Sub shfdohfs()


 731 Exit Sub
 
 'Error Handler
 ErrorRecord:



 'Resume
 734 Resume Next

 End Sub

within one sub-routine you can jump to a label but that label MUST be inside the same sub-routine. You have your ErrorRecord label in a DIFFERENT sub-routine and that's why you get an error
 
Upvote 0
Thank you.

In which case (and being that the code takes a whole day to run) will the Resume Next still run as required if left where it is?
 
Upvote 0
Well

1) As it is your code won't run because it won't compile
2) If you take out your GoTo command then the code won't get to your resume (At least via that route) so the answer to your question is no
 
Upvote 0
Not based on what little you've posted because it will never be executed.
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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