View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default VBA code crashes Excel 97 - Help please!

I couldn't reproduce what I understood as being your problem in Excel 97
with this test

Range("A1").Formula = "=1/0" ' #DIV/0!
Range("B1").Value = Range("A1").Value
v = Range("B1").Value
If IsError(v) Then v = Range("B1").Text ' #DIV/0!
MsgBox v

Could you isolate the particular value that causes the problem and
demonstrate with simplified code, indicate the line that causes the crash.

Regards,
Peter T

"GB" wrote in message
...
Hi, I have some simple code (below) that works most of the time.
Unfortunately, if there is an error in the data in the spreadsheet, this

can
cause some of the values in the spreadsheet to go N/A, 'Not a value',

Div/0
or something similar. The result is not just that the macro stops working,
but it crashes Excel completely. Is this normal expected behaviour from
Excel 97? What is the best way to trap the errors, so it just keeps

working
and either leaves a blank in my results page or copies the N/A figures,

then
moves onto the next case?

Can I put in something like:
On Error Resume Next

(You can see that I was brought up on GW-Basic.)


--------------------------------------------------------------------------

----------------------
Here is the VBA code:

Public Sub DoAllCalcs()


For JJ = 1 To 740 ' Use 1 for first case, up to no. of cases

Sheets("Basic Info").Range("C1").Value = JJ 'Increments case no. to get

data
from database

Calculate

Sheets("ResultsList").Range("A" & JJ + 3).Value = JJ

Sheets("ResultsList").Range("B" & JJ + 3).Value =
Sheets("Summary").Range("C4")
Sheets("ResultsList").Range("C" & JJ + 3).Value =
Sheets("Summary").Range("C25")
Sheets("ResultsList").Range("D" & JJ + 3).Value =
Sheets("Summary").Range("D25")
Sheets("ResultsList").Range("E" & JJ + 3).Value =
Sheets("Summary").Range("E25")
Sheets("ResultsList").Range("F" & JJ + 3).Value =
Sheets("Summary").Range("F25")
Sheets("ResultsList").Range("H" & JJ + 3).Value =
Sheets("Summary").Range("G31")
Sheets("ResultsList").Range("I" & JJ + 3).Value =
Sheets("Summary").Range("C35")
Sheets("ResultsList").Range("J" & JJ + 3).Value =
Sheets("PastCalcs").Range("I5")
Sheets("ResultsList").Range("K" & JJ + 3).Value =
Sheets("PastCalcs").Range("Q5")

Debug.Print JJ

Next


End Sub