PDA

View Full Version : crashing on closing



northernstar
09-04-2007, 01:58 PM
hi everyone

i have wrote some code for a spreadsheet and it all works fine but on some pcs and not everytime the spreadsheet just freezes and the egg timer just hangs on the screen

could someone have a look and let me know what the problem is and ideas on how to fix it

i would also welcome any comments regarding the coding as i am still quite a novice on it, even though i have been doing it for sometime now

thanks

mdmackillop
09-04-2007, 02:39 PM
Recording code leaves a lot of excess, particularly Selection. This can be removed and the Range referred to directly. Also, instead of multiple If statements, check out Select Case.

E.G.

Select Case Range("Sheet1!M32")
Case 1
Sheets("Sheet1").Range("B12:K12").Copy Sheets("Certificate").Range("A17")
Sheets("Sheet1").Range("b33:d41").Copy Sheets("Certificate").Range("A19")
If Range("Sheet1!c48") = 4 Then
Range("Certificate!f17").ClearContents
End If

Case 2
Sheets("Sheet1").Range("B12:K13").Copy Sheets("Certificate").Range("A17")
Sheets("Sheet1").Range("b33:d41").Copy Sheets("Certificate").Range("A20")
If Range("Sheet1!c48") = 4 Then
Range("Certificate!f17:f18").ClearContents
End If
Case 3 'etc.
End Select

northernstar
09-04-2007, 02:45 PM
would that cause it to hang up sometimes?

thanks for your help and advice

mdmackillop
09-04-2007, 02:47 PM
I've not found that cause yet, but slimmer code helps too!

northernstar
09-04-2007, 02:51 PM
ok no problem will leave it with you and i will amend the code as suggested

thanks again

mdmackillop
09-04-2007, 04:18 PM
I don't see any reason, so I'll fall back to saying it's probably a corrupt file. I tried copying the form and cell data to a new book, but with the same results.

northernstar
09-04-2007, 11:00 PM
so are you suggesting that i just start again in a new book?

or is that what you have tried, didn t quite understand you last message

thanks again

mdmackillop
09-04-2007, 11:57 PM
That is what I would do. Recreate the form layout. Copy and paste the code text etc.

rory
09-05-2007, 02:39 AM
I've gone through your code and made a few alterations to remove unnecessary selections and to shorten some of it - you may want to give it a try.