View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to keep excel from crashing?

I tested this abbreviated version just to be sure (I doubted the number of
the loops in and of itself were problematic)

Private Sub Tester()

Dim StartPrice As Variant
Dim SharesOut As Variant
Dim NewPrice As Variant
Dim Cash As Variant
Dim ATIIPerShare As Variant
Dim PriceApprec As Variant
Dim SharePurch As Variant
Dim MarketCap As Variant
Dim Interest As Variant
Dim Tax As Variant

Cash = 56407000000#
StartPrice = 27.64
SharesOut = 10770000724#
MarketCap = 297876300000#
Interest = 0.05
Tax = 0.33

For SharePurch = 1 To 10770000724#
Next
Debug.Print SharePurch
End Sub

and it ran with no problem

xl2000, win2000

Crash is not very definitive - what happens? If you get an error, what is
it and what line is highlighted?

--
Regards,
Tom Ogilvy

"Keith" wrote in message
om...
Any ideas on how to keep excel from crashing while running the
following? Is asking it to do a for loop with 10 billion iterations
simply too much?

Thanks in advance,

Keith

Private Sub CommandButton1_Click()

Dim StartPrice As Variant
Dim SharesOut As Variant
Dim NewPrice As Variant
Dim Cash As Variant
Dim ATIIPerShare As Variant
Dim PriceApprec As Variant
Dim SharePurch As Variant
Dim MarketCap As Variant
Dim Interest As Variant
Dim Tax As Variant

Cash = 56407000000#
StartPrice = 27.64
SharesOut = 10770000724#
MarketCap = 297876300000#
Interest = 0.05
Tax = 0.33

For SharePurch = 1 To 10770000724#

SharesOut = SharesOut - 1

NewPrice = MarketCap / SharesOut

Cash = Cash - NewPrice

ATIIPerShare = ((Cash * Interest) * (1 - Tax)) / SharesOut

PriceApprec = NewPrice - StartPrice

If ATIIPerShare = PriceApprec Then
MsgBox ("Shares Repurchased = " & SharesPurch & " and New
Cash Balance = " & Cash)
Exit For
End If

Next

End Sub