Я хочу Exit Sub
, если моя Function
процедура (Colvalidation
) не находит столбец из массива ниже. Я знаю, что невозможно End Sub
в пределах Function
, и я понятия не имею, как с этим справиться. Не могли бы вы помочь мне с этим?
Sub test()
(...)
'Check if "Earnings", "Deductions", "Employer" headers exist
vals = Array("Earnings", "Deductions", "Employer")
vals = Array("Earnings", "Deductions", "Employer Paid Benefits and Taxes")
Set myRng = Worksheets(PayrollWS).Range(Worksheets(PayrollWS).Cells(MyR, 1), Worksheets(PayrollWS).Cells(MyR, 25))
For Each val In vals
Colvalidation myRng, val
If ColFound = False Then 'error = "Variable not defined"
Exit Sub
Next
(...)
End Sub
Function Colvalidation(Rng As Range, value As Variant)
Dim rngX As Range, ColFound as Boolean
Set rngX = Rng.Find(what:=value, lookat:=xlPart, LookIn:=xlValues)
If rngX Is Nothing Then
MsgBox value & " - Column Not Found" 'if column not found, Exit Sub after MsgBox
ColFound = False
Exit Function
End If
End Function