Exit Sub?

  • Thread starter Thread starter Eva Shanley
  • Start date Start date
E

Eva Shanley

Hello, I could use some help with my code. This code
checks to make sure there are dates in Col. E for every
every entry in Col. C. The first problem I have is if I
click OK in the MsgBox and OK in the InputBox, the macro
stops without forcing me to enter a date. The second
problem is that I'd like this macro to execute first, then
call several others. Even if this macro stops executing,
the others behind it run. It doesn't look like Exit Sub
will do what I need either, and if a date is missing in
Col. E, I really need to force the user to input the date,
have the date check macro finish checking Col. E, and then
call the other macros. What am I missing (maybe Santa will
bring me a brain)? Any help will be much appreciated!

Sheets("Pacc AD").Select
Range("C24").Select
Dim Value1
Do Until ActiveCell = ""

If ActiveCell <> "" And ActiveCell.Offset(0, 2) <> "" Then
ActiveCell.Offset(1, 0).Select

Else: Check = MsgBox("Missing date in Column E!",
vbCritical, "Please check your dates!")
ActiveCell.Offset(0, 2).Select
Value1 = InputBox("Enter the missing date")
ActiveCell.FormulaR1C1 = Value1
ActiveCell.Offset(1, -2).Range("A1").Select

End If
Loop
End Sub
 
Hi

Part answer only:
You want a macro to return an "OK, go on", if not do not run the other macros ? Macros
that return something are Functions. Or better; macros are functions that return nothing,
"Void" in other programming languages. See if this sample can be of use -run Main:

Sub Main()
If Something = True Then
Call Anything
Call Everything
End If
End Sub

Function Something() As Boolean
Something = False
If InputBox("Enter something:") <> "" Then _
Something = True
End Function

Sub Anything()
MsgBox "Anything goes"
End Sub

Sub Everything()
MsgBox "Everything goes"
End Sub
 
Hi

I am sure there is a better way to do this, but just modifying your code a
little like this using columns D and E seems to work ok.


Sheets("Pacc AD").Select
Range("D1").Select

Dim Value1
Dim check As Integer

Do Until ActiveCell = ""

If ActiveCell.Offset(0, 1) = "" Then

check = MsgBox("Missing date in Column E!", vbOKCancel + vbCritical, "Please
check your dates!")
If check = vbCancel Then Exit Sub

tryagain:

Value1 = InputBox("Enter the missing date using the format....
DD/MM/YYYY")

If Value1 = "" Then
MsgBox "You must enter a date like.... 29/05/2004"
GoTo tryagain
End If

ActiveCell.Offset(0, 1).Value = Value1


End If

ActiveCell.Offset(1, 0).Select
Loop
End Sub


HTH

Ken
 
Back
Top