Hi All,
I'm pretty new to VBA so I'm hoping someone can point and laugh at my mistake and tell me what's going on.
I'm using Excel 2010 on a Windows 7 (x64 pro) machine. I have the following code:
When the code reaches the point where the comment about crashing is, Excel crashes. Originally I didn't have all the message boxes you see, but I added them to debug. As you can see, the crash will happen even between just two message boxes. The first one will appear, I click "okay" and then before the second one will appear, the whole application crashes.
At first I thought it might be related to something in the Userform that I'm setting up, but since it still occurs between message boxes, I'm thinking the UserForm is unrelated?
I have found a workaround, if the file is saved before running the procedure, then it works fine. I have temporarily set it up to save when the file opens, but as the file gets larger over time, that may not be a long term solution.
As I said, I'm hoping it's something stupid simple that I missed. Any Ideas?
I'm pretty new to VBA so I'm hoping someone can point and laugh at my mistake and tell me what's going on.
I'm using Excel 2010 on a Windows 7 (x64 pro) machine. I have the following code:
Code:
Sub UpdateGroup()
Dim Count As Long
Dim TextNum As String
UpdateGrp = True
Application.ScreenUpdating = False
YesError = False ' This is setup so if a group isn't found after hitting update, the sub doesn't incorrectly fill fields
Call FindGroup
'Load UserForm1
If ActiveCell.Value = "" Or SearchName = "" Then
Sheets("Display").Activate
Exit Sub
End If
If YesError = True Then ' If no company is found after hitting update button, then it acts as a new group
Call ShowUserform
Sheets("Display").Activate
Exit Sub
End If
Sheets("Records").Activate
For Count = 1 To 236
TextNum = "Textbox" & Count
UserForm1.Controls(TextNum).Value = ActiveCell.Offset(0, Count).Value
Next Count
MsgBox "Userform command buttion is visible = " & UserForm1.CommandButton1.Visible 'debugging message
UserForm1.CommandButton1.Visible = False
MsgBox "Userform command buttion is visible = " & UserForm1.CommandButton1.Visible 'debugging message
'Crash will appear here even between the two message boxes
MsgBox "ComboBox 1 value is now: " & UserForm1.ComboBox1.Text 'debugging message
UserForm1.ComboBox1.Text = UserForm1.TextBox72.Text
MsgBox "ComboBox 1 value is now: " & UserForm1.ComboBox1.Text 'debugging message
UserForm1.ComboBox2.Text = UserForm1.TextBox132.Text
UserForm1.ComboBox3.Text = UserForm1.TextBox181.Text
MsgBox "Combo boxes now loaded"
UserForm1.Show
Application.ScreenUpdating = True
End Sub
At first I thought it might be related to something in the Userform that I'm setting up, but since it still occurs between message boxes, I'm thinking the UserForm is unrelated?
I have found a workaround, if the file is saved before running the procedure, then it works fine. I have temporarily set it up to save when the file opens, but as the file gets larger over time, that may not be a long term solution.
As I said, I'm hoping it's something stupid simple that I missed. Any Ideas?