Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Macro not exiting correctly

The following macro was working to solve for face. But in case the solver
couldn't determine the face amount - I wanted to handle this error message.

Solver can get the correct face amount - however it will still display the
message box. What am I doing wrong??



Sub Solve_for_Face()
Dim cntr As Integer
If shtSolve.Range("z19").Value < 5000 Then
shtSolve.Range("z19").Value = 5000
End If
shtSolve.Range("aa25").GoalSeek Goal:=shtSolve.Range("aa26"), _
ChangingCell:=shtSolve.Range("z19")

Do
On Error GoTo newprem
shtSolve.Range("z19").Value = Round(shtSolve.Range("z19").Value, 3)
+ 0.001

Loop Until shtSolve.Range("aa25").Value shtSolve.Range("aa26").Value
shtSolve.Range("z19").Value = shtSolve.Range("z19").Value - 0.001
shtSummary.Range("UnitAmt") = Int(shtSolve.Range("z19") * 1000)
shtSummary.Range("UnitADB") = Int(shtSolve.Range("z21") * 1000)
Exit Sub
newprem:
MsgBox "cannot solve for face enter different premium"
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro not exiting correctly

I would remove the On Error statement to see what really is causing the
error. make the On Error statement a comment by putting a single quote in
front of the line. Then run the code to find the cause of the error.

"Brad" wrote:

The following macro was working to solve for face. But in case the solver
couldn't determine the face amount - I wanted to handle this error message.

Solver can get the correct face amount - however it will still display the
message box. What am I doing wrong??



Sub Solve_for_Face()
Dim cntr As Integer
If shtSolve.Range("z19").Value < 5000 Then
shtSolve.Range("z19").Value = 5000
End If
shtSolve.Range("aa25").GoalSeek Goal:=shtSolve.Range("aa26"), _
ChangingCell:=shtSolve.Range("z19")

Do
On Error GoTo newprem
shtSolve.Range("z19").Value = Round(shtSolve.Range("z19").Value, 3)
+ 0.001

Loop Until shtSolve.Range("aa25").Value shtSolve.Range("aa26").Value
shtSolve.Range("z19").Value = shtSolve.Range("z19").Value - 0.001
shtSummary.Range("UnitAmt") = Int(shtSolve.Range("z19") * 1000)
shtSummary.Range("UnitADB") = Int(shtSolve.Range("z21") * 1000)
Exit Sub
newprem:
MsgBox "cannot solve for face enter different premium"
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Macro not exiting correctly

There are situations where an individual can input a premium that is not
sufficient for the minimum face amount.

The macro correctly comes up with the correct face amount when a valid
premium is inputted - however it still show the message box.

"Brad" wrote:

The following macro was working to solve for face. But in case the solver
couldn't determine the face amount - I wanted to handle this error message.

Solver can get the correct face amount - however it will still display the
message box. What am I doing wrong??



Sub Solve_for_Face()
Dim cntr As Integer
If shtSolve.Range("z19").Value < 5000 Then
shtSolve.Range("z19").Value = 5000
End If
shtSolve.Range("aa25").GoalSeek Goal:=shtSolve.Range("aa26"), _
ChangingCell:=shtSolve.Range("z19")

Do
On Error GoTo newprem
shtSolve.Range("z19").Value = Round(shtSolve.Range("z19").Value, 3)
+ 0.001

Loop Until shtSolve.Range("aa25").Value shtSolve.Range("aa26").Value
shtSolve.Range("z19").Value = shtSolve.Range("z19").Value - 0.001
shtSummary.Range("UnitAmt") = Int(shtSolve.Range("z19") * 1000)
shtSummary.Range("UnitADB") = Int(shtSolve.Range("z21") * 1000)
Exit Sub
newprem:
MsgBox "cannot solve for face enter different premium"
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro not exiting correctly

The only way the message box can appear on an error because of the exit sub
statement. therefore, you must have an error to get the message box.

If you don't want to remove the On Error statement. Then you can break the
code by pressing Ctrl Break when the message box incorrectly appears. Then
look at the values in Z19 to give a clue to the source of the problem.

"Brad" wrote:

There are situations where an individual can input a premium that is not
sufficient for the minimum face amount.

The macro correctly comes up with the correct face amount when a valid
premium is inputted - however it still show the message box.

"Brad" wrote:

The following macro was working to solve for face. But in case the solver
couldn't determine the face amount - I wanted to handle this error message.

Solver can get the correct face amount - however it will still display the
message box. What am I doing wrong??



Sub Solve_for_Face()
Dim cntr As Integer
If shtSolve.Range("z19").Value < 5000 Then
shtSolve.Range("z19").Value = 5000
End If
shtSolve.Range("aa25").GoalSeek Goal:=shtSolve.Range("aa26"), _
ChangingCell:=shtSolve.Range("z19")

Do
On Error GoTo newprem
shtSolve.Range("z19").Value = Round(shtSolve.Range("z19").Value, 3)
+ 0.001

Loop Until shtSolve.Range("aa25").Value shtSolve.Range("aa26").Value
shtSolve.Range("z19").Value = shtSolve.Range("z19").Value - 0.001
shtSummary.Range("UnitAmt") = Int(shtSolve.Range("z19") * 1000)
shtSummary.Range("UnitADB") = Int(shtSolve.Range("z21") * 1000)
Exit Sub
newprem:
MsgBox "cannot solve for face enter different premium"
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Macro not exiting correctly

Okay you're right
Removing the On Error statement I get a
"Run=time error -2177417848(80010108)
Method "hidden" of object 'range' failed.

Not what I expected - haven't had this error ever before. need to do some
more looking

"Joel" wrote:

The only way the message box can appear on an error because of the exit sub
statement. therefore, you must have an error to get the message box.

If you don't want to remove the On Error statement. Then you can break the
code by pressing Ctrl Break when the message box incorrectly appears. Then
look at the values in Z19 to give a clue to the source of the problem.

"Brad" wrote:

There are situations where an individual can input a premium that is not
sufficient for the minimum face amount.

The macro correctly comes up with the correct face amount when a valid
premium is inputted - however it still show the message box.

"Brad" wrote:

The following macro was working to solve for face. But in case the solver
couldn't determine the face amount - I wanted to handle this error message.

Solver can get the correct face amount - however it will still display the
message box. What am I doing wrong??



Sub Solve_for_Face()
Dim cntr As Integer
If shtSolve.Range("z19").Value < 5000 Then
shtSolve.Range("z19").Value = 5000
End If
shtSolve.Range("aa25").GoalSeek Goal:=shtSolve.Range("aa26"), _
ChangingCell:=shtSolve.Range("z19")

Do
On Error GoTo newprem
shtSolve.Range("z19").Value = Round(shtSolve.Range("z19").Value, 3)
+ 0.001

Loop Until shtSolve.Range("aa25").Value shtSolve.Range("aa26").Value
shtSolve.Range("z19").Value = shtSolve.Range("z19").Value - 0.001
shtSummary.Range("UnitAmt") = Int(shtSolve.Range("z19") * 1000)
shtSummary.Range("UnitADB") = Int(shtSolve.Range("z21") * 1000)
Exit Sub
newprem:
MsgBox "cannot solve for face enter different premium"
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro not working correctly Brad Excel Programming 2 March 28th 07 12:55 AM
Macro suffers from premature exiting Fred Smith Excel Programming 6 February 14th 07 01:57 AM
Macro not calculating correctly Ozgur Pars[_2_] Excel Programming 0 July 17th 06 03:53 PM
Macro Fails to Run Correctly JK Excel Programming 3 August 20th 04 09:40 PM
Exiting a VBA Macro by user intervention JON Excel Programming 1 April 23rd 04 06:01 PM


All times are GMT +1. The time now is 10:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"