Reputation: 175
Why my userform shows "Not Responding" when I run the following code? I have been trying to resolve it, but it is not resolved yet.
Actually it works sometimes. I think the problem has something to do with the screen updating.
' The input button in Sheet1
Sub Rectangle1_Click()
'Remember time when macro starts
StartTime = Timer
' To improve speed and performance
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
' Show the userform
UserForm1.Show vbModeless
UserForm1.Label1.Caption = "Calculation in progress ... " & vbNewLine & "Please be patient"
UserForm1.Label1.Font.Size = 12
UserForm1.Top = (Application.Height / 2) - (UserForm1.Height / 2)
UserForm1.Left = (Application.Width / 2) - (UserForm1.Width / 2)
UserForm1.CommandButton1.Visible = False
UserForm1.Repaint
Call Insert_RawData
'Determine how many seconds code took to run
SecondsElapsed = Round(Timer - StartTime, 2)
UserForm1.Label1.Caption = "This code ran successfully in " & SecondsElapsed & " seconds"
UserForm1.CommandButton1.Visible = True
' Return back to the original settings
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationSemiautomatic
End Sub
Upvotes: 1
Views: 1288
Reputation: 564
It could be a number of things. If the issue is intermittent like you mention, then in all likelihood the program IS working, and Windows is just labeling it non-responsive because the program is working too hard to respond to the OS.
The likely issue is probably one, or a combination, of the following:
Insert_RawData
Insert_RawData
is encountering an error due to a bad/unhandled value in one of the cells it works with (less likely)Some suggestions to try and narrow the source down:
Insert_RawData
and watch it run to see if it's hitting an error
Insert_RawData
and break points on the code handling the case that the error check failsUnless you are hitting an error in Insert_RawData
though, it's likely that the macro WILL complete, it just might take a really long time.
Upvotes: 1