![]() |
Ending Procedure When Condition is Met Anywhere in Procedure
I have a file I use to reconcile 2 sets of numbers. What I would like is to
end the procedure the moment the difference between the numbers is 0. The way my file works is that when the file is opened, I am prompted to enter information into cells through a series of Input Boxes. At certain points, I make the macro stop if the cell containing the difference equals 0. It works great, but I would like to have the macro stop the moment the difference = 0. Here is my macro: Private Sub Test() 'Enters information Application.StatusBar = "Enter information." Entry = MsgBox("Activate Wizard?", vbQuestion + vbYesNo, "Data Entry") If Entry = vbYes Then Application.Run (Macro) Else: Call Messages.Messages End End If 'Prompts to enter Target and Data1 Range("Target").Value = InputBox("Enter target figu", "Wizard: Target") Range("1").Value = InputBox("Enter Figure1 amount:", "Wizard: Figure1") Range("2").Value = InputBox("Enter Figure2 amount:", "Wizard: Figure2") Range("3").Value = InputBox("Enter Figure3 amount:", "Wizard: Figure3") If Range("Difference").Value = 0 Then Sheets(2).Activate End End If 'Prompts to enter Data2 if Difference < 0 Data2 = MsgBox("Is there Data2?", vbQuestion + vbYesNo, "Data2") If Data2 = vbYes Then Range("4").Value = InputBox("Enter Figure4 amount:", "Wizard: Figure4") Range("5").Value = InputBox("Enter Figure5 amount:", "Wizard: Figure5") Range("6").Value = InputBox("Enter Figure6 amount:", "Wizard: Figure6") End If If Range("Difference").Value = 0 Then Sheets(2).Activate End End If 'Prompts to enter Data3 if Difference < 0 Data3 = MsgBox("Enter Data3?", vbQuestion + vbYesNo, "Data3") If Data3 = vbYes Then Range("7").Value = InputBox("Enter Figure7:", "Wizard: Figure7") Range("8").Value = InputBox("Enter Figure8 amount:", "Wizard: Figure8") Range("9").Value = InputBox("Enter Figure9:", _ "Wizard: Figure9", Abs(Range("Difference").Value)) End If 'Displays report Sheets(2).Activate Call Messages.Messages End Sub You'll notice the recurring code: If Range("Difference").Value = 0 Then Sheets(2).Activate End End If I want to enter that once in my module and execute that IF statement the moment it is true. Thanks. (The numbered range names are fake; I know they are illegal in Excel) -- I am running on Excel 2003, unless otherwise stated. |
Ending Procedure When Condition is Met Anywhere in Procedure
Just a note:
I would like this to start searching after I enter my target figure. |
Ending Procedure When Condition is Met Anywhere in Procedure
I found a workaround with a separate procedure I call after each point in
data entry. |
All times are GMT +1. The time now is 09:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com