Excel Crashing - Problem in VB Code

clloydy

New Member
Joined
Sep 9, 2010
Messages
3
I am currently building a tool that incorporates a variety of macros. These range from simple macros to the more complex and include setting full screen and focus, disabling buttons and changing displayed images based on access levels stored on worksheets, putting password prompts on userforms to access other userforms, etc.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
However, I seem to have an issue where excel crashes frequently, at least twice per hour, I’ve tried re-installing Microsoft Office and Windows but the problem still persists. It is also happening on other machines.<o:p></o:p>
It frequently happens when trying to save the file, and comes up with the following error message:<o:p></o:p>
Problem signature:<o:p></o:p>
Problem Event Name: APPCRASH<o:p></o:p>
Application Name: EXCEL.EXE<o:p></o:p>
Application Version: 12.0.4518.1014<o:p></o:p>
Application Timestamp: 45428263<o:p></o:p>
Fault Module Name: VBE6.DLL<o:p></o:p>
Fault Module Version: 6.5.10.20<o:p></o:p>
Fault Module Timestamp: 45187577<o:p></o:p>
Exception Code: c0000005<o:p></o:p>
Exception Offset: 00111497<o:p></o:p>
OS Version: 6.1.7600.2.0.0.256.48<o:p></o:p>
Locale ID: 2057<o:p></o:p>
<o:p></o:p>
Additional information about the problem:<o:p></o:p>
LCID: 1033<o:p></o:p>
Brand: Office12Crash<o:p></o:p>
skulcid: 1033<o:p></o:p>
<o:p></o:p>
It also crashes when I am initiating or editing userforms, this is normally when I have changed the VB code (and crashes both when accessing particular forms or modules and on the worksheets). A common message is ‘Object not found.’ When I click on debug it displays the module that calls the userform and highlights the line ‘Userform1.Show’, which is in fact there and works previously.<o:p></o:p>
The Workbook has to go out to a client who will only have limited access to the worksheet and will not be able to edit the VBA code. I’m guessing it must be an error in part of the code that is causing the worksheet to crash but I’m not sure what to look for, as all the code seems to work but it just crashes at random intervals. If anyone could suggest what could be causing this and what I should be looking for it would be greatly appreciated.<o:p></o:p>
Many Thanks,<o:p></o:p>
Chris<o:p></o:p>
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
The spreadsheet is very large and I am working to a deadline so remaking the sheet would have to be a last resort. However, I think I might have narrowed it down to the following code:

The below code comes from a userform I am using and is designed to initialise the userform and find the next value in a column that is not equal to 1.

Private Sub UserForm_Initialize()
ActiveWorkbook.Sheets("Auditors").Activate
Range("N13").Select
Do
If [ActiveCell] = 1 Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell.Value <> 1
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
UniqueID.Caption = ActiveCell.Offset(0, 3).Value
FirstName.Value = ""
LastName.Value = ""
Company.Value = ""
ContactNumber.Value = ""
PasswordCheckBox = True
With Status
.AddItem "Active"
.AddItem "Inactive"
End With
FirstName.SetFocus
End Sub

Then the following code is designed to input the data entered on the userform into cells on that row then close the userform, the code for this is:

Private Sub Ok_Click()
ActiveCell.Offset(0, 6) = FirstName.Value
ActiveCell.Offset(0, 7) = LastName.Value
ActiveCell.Offset(0, -10) = Company.Value
ActiveCell.Offset(0, -9) = ContactNumber.Value
ActiveCell.Offset(0, -8) = Status.Value

If PasswordCheckBox = True Then
ActiveCell.Offset(0, 8) = Password.Value
Else: ActiveCell.Offset(0, 8) = ""
End If
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Unload Me
End Sub


This code works but I think it may be causing the system to crash. Could the active cell referencing be conflicting with other modules running in the background, if so would there be a way i could change the code so that it wasn't referenced to the active cell?

Thanks,
Chris
 
Upvote 0
I would avoid activating cells altogether. For example your first routine could be written as

Code:
Private Sub UserForm_Initialize()
Dim r As Range
ActiveWorkbook.Sheets("Auditors").Activate
Set r = Range("N13")
Do
    If r.Value = 1 Then
        Set r = r.Offset(1)
    End If
Loop Until r.Value <> 1
UniqueID.Caption = r.Offset(0, 3).Value
FirstName.Value = ""
LastName.Value = ""
Company.Value = ""
ContactNumber.Value = ""
PasswordCheckBox = True
With Status
    .AddItem "Active"
    .AddItem "Inactive"
End With
FirstName.SetFocus
End Sub
 
Upvote 0
Thankyou I don't think ive solved the crashing issue but that's a much more streamlined way of carrying out what I was trying to achieve. If possible would you be able to show me how to start the previous and next user buttons on the form using this method, they were previously coded starting like this:

Private Sub Previous_Click()
ActiveCell.Offset(-1, 0).Select
'Then I had code to populate the userform with the current data in that row
 
Upvote 0
It would have helped to see a bit more of your code but something like the following should work

Code:
Private Sub Previous_Click()
Dim r As Range
Set r = ActiveCell.Offset(-1, 0)
userform1.textbox1.Text = r.Value
userform.textbox2.Text = r.Offset(, 1).Value
 
Upvote 0

Forum statistics

Threads
1,215,249
Messages
6,123,882
Members
449,130
Latest member
lolasmith

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top