Billdub417
New Member
- Joined
- Nov 5, 2019
- Messages
- 45
Hello,
I have some code that checks for errors in some cells before proceeding.
I need to use this error checking code in another VBA, however, rather than duplicate the code, is there a way to split this into a separate Sub, "CALL" it from both codes where it is being used, and if it flags an error, cancel the original VBA.
When I have tried splitting this out previously, the original code continued despite any errors (as if there were errors, it's just set to "Exit Sub")
Glad of any advice, Many thanks.
I have some code that checks for errors in some cells before proceeding.
I need to use this error checking code in another VBA, however, rather than duplicate the code, is there a way to split this into a separate Sub, "CALL" it from both codes where it is being used, and if it flags an error, cancel the original VBA.
When I have tried splitting this out previously, the original code continued despite any errors (as if there were errors, it's just set to "Exit Sub")
Glad of any advice, Many thanks.
VBA Code:
Sub CheckErrors()
With Sheet5
Dim cell As Range
Dim i As Integer
i = 1
For Each cell In .Range("D620:o620").Cells
If cell.value <> 0 Then
If cell.value <> "" Then
MsgBox ("Sheet" & i & " does not balance")
Exit Sub
End If
End If
i = i + 1
Next
End With
With Sheet27
Dim cell1 As Range
Dim j As Integer
j = 1
For Each cell1 In .Range("e108:p108").Cells
If cell1.value <> 0 Then
MsgBox ("Line" & j & " does not balance")
Exit Sub
End If
j = j + 1
Next
End With
End Sub