VBA Macro makes Excel crash... what are the causes to investigate?

Malkavian

New Member
Joined
Jul 22, 2010
Messages
16
Hi!

So I made this big business program that basicly import huge data tables from an Access database to Excel sheets. The user enter a group number in input and the datas of that specific group are shown on the userform. The program allows to add, remove and edit groups and those modifications are exported back to the Access database. The program is HUGE. I have hundreds of textboxes and thousands of lines of datas.

Everything worked fine but now, one button makes Excel crash... I can't figure what's the problem is since when I run the macro assigned to that button step by step (with F8), the macro runs just fine. :eek:

What should I investigate?? Never had this kind of issue with VBA before... :confused:
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Malkavian

New Member
Joined
Jul 22, 2010
Messages
16
Oh and here's the code for the problematic button :

Private Sub cmdBack_Click()
TextBoxAn.Text = ""
TextBoxAnB.Text = ""
TextBoxAnC.Text = ""
TextBoxAnD.Text = ""
TextBoxAnE.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox3B.Text = ""
TextBox3C.Text = ""
TextBox3D.Text = ""
TextBox3E.Text = ""
TextBox4.Text = ""
TextBox4B.Text = ""
TextBox4C.Text = ""
TextBox4D.Text = ""
TextBox4E.Text = ""
TextBox5.Text = ""
TextBox5B.Text = ""
TextBox5C.Text = ""
TextBox5D.Text = ""
TextBox5E.Text = ""
TextBox6.Text = ""
TextBox6B.Text = ""
TextBox6C.Text = ""
TextBox6D.Text = ""
TextBox6E.Text = ""
TextBox7.Text = ""
TextBox7B.Text = ""
TextBox7C.Text = ""
TextBox7D.Text = ""
TextBox7E.Text = ""
TextBox8.Text = ""
TextBox8B.Text = ""
TextBox8C.Text = ""
TextBox8D.Text = ""
TextBox8E.Text = ""
TextBox9.Text = ""
TextBox9B.Text = ""
TextBox9C.Text = ""
TextBox9D.Text = ""
TextBox9E.Text = ""
TextBox10.Text = ""
TextBox10B.Text = ""
TextBox10C.Text = ""
TextBox10D.Text = ""
TextBox10E.Text = ""
TextBox11.Text = ""
TextBox11B.Text = ""
TextBox11C.Text = ""
TextBox11D.Text = ""
TextBox11E.Text = ""
TextBox12.Text = ""
TextBox12B.Text = ""
TextBox12C.Text = ""
TextBox12D.Text = ""
TextBox12E.Text = ""
TextBox13.Text = ""
TextBox13B.Text = ""
TextBox13C.Text = ""
TextBox13D.Text = ""
TextBox13E.Text = ""
TextBox14.Text = ""
TextBox14B.Text = ""
TextBox14C.Text = ""
TextBox14D.Text = ""
TextBox14E.Text = ""
TextBox15.Text = ""
TextBox15B.Text = ""
TextBox15C.Text = ""
TextBox15D.Text = ""
TextBox15E.Text = ""
TextBox16.Text = ""
TextBox16B.Text = ""
TextBox16C.Text = ""
TextBox16D.Text = ""
TextBox16E.Text = ""
TextBox17.Text = ""
TextBox17B.Text = ""
TextBox17C.Text = ""
TextBox17D.Text = ""
TextBox17E.Text = ""
TextBox18.Text = ""
TextBox18B.Text = ""
TextBox18C.Text = ""
TextBox18D.Text = ""
TextBox18E.Text = ""
TextBox19.Text = ""
TextBox20.Text = ""
TextBox21.Text = ""
TextBox22.Text = ""
TextBox24.Text = ""
TextBox25.Text = ""
TextBox26.Text = ""
TextBox27.Text = ""
TextBox28.Text = ""
TextBox29.Text = ""
TextBox30.Text = ""
TextBox31.Text = ""
TextBox32.Text = ""
TextBox33.Text = ""
TextBox34.Text = ""
TextBox36.Text = ""
TextBox37.Text = ""
TextBox38.Text = ""
TextBox39.Text = ""
TextBox40.Text = ""
TextBox41.Text = ""
TextBox42.Text = ""
TextBox43.Text = ""
TextBox44.Text = ""
TextBox45.Text = ""
TextBox46.Text = ""
TextBox47.Text = ""
TextBox48.Text = ""
TextBox49.Text = ""
TextBox50.Text = ""
TextBox51.Text = ""
TextBox53.Text = ""
TextBox54.Text = ""
TextBox55.Text = ""
TextBox56.Text = ""
TextBox57.Text = ""
TextBox58.Text = ""
TextBox59.Text = ""
TextBox60.Text = ""
TextBox61.Text = ""
TextBox62.Text = ""
TextBox63.Text = ""
TextBox64.Text = ""
TextBox65.Text = ""
TextBox66.Text = ""
TextBox67.Text = ""
TextBox68.Text = ""
TextBox69.Text = ""
TextBox70.Text = ""
TextBox71.Text = ""
TextBox72.Text = ""
TextBox74.Text = ""
TextBox75.Text = ""
TextBox76.Text = ""
TextBox78.Text = ""
TextBox79.Text = ""
TextBoxAnn.Text = ""
TextBoxAnnB.Text = ""
TextBoxAnnC.Text = ""
TextBoxAnnD.Text = ""
TextBoxAnnE.Text = ""
TextBoxAnnF.Text = ""
TextBoxAnnG.Text = ""
TextBoxAnnH.Text = ""
TextBoxAnnI.Text = ""
TextBoxAnnJ.Text = ""
TextBoxAnnK.Text = ""
TextBoxAnnL.Text = ""
TextBoxAnnM.Text = ""
TextBoxAnnN.Text = ""
TextBoxAnnO.Text = ""
TextBoxAnnP.Text = ""
TextBoxAnnQ.Text = ""
TextBoxAnnR.Text = ""
TextBoxAnnS.Text = ""
TextBoxAnnT.Text = ""
TextBoxAnnU.Text = ""
TextBoxAnnV.Text = ""
TextBoxAnnW.Text = ""
TextBoxAnnX.Text = ""
TextBoxAnnY.Text = ""
TextBoxAnnZ.Text = ""
TextBoxAnnAA.Text = ""
TextBoxAnnAB.Text = ""
TextBoxAnnAC.Text = ""
TextBoxAnnAD.Text = ""
TextBox80.Text = ""
TextBox80B.Text = ""
TextBox80C.Text = ""
TextBox80D.Text = ""
TextBox80E.Text = ""
TextBox80F.Text = ""
TextBox80G.Text = ""
TextBox80H.Text = ""
TextBox80I.Text = ""
TextBox80J.Text = ""
TextBox80K.Text = ""
TextBox80L.Text = ""
TextBox80M.Text = ""
TextBox80N.Text = ""
TextBox80O.Text = ""
TextBox80P.Text = ""
TextBox80Q.Text = ""
TextBox80R.Text = ""
TextBox80S.Text = ""
TextBox80T.Text = ""
TextBox80U.Text = ""
TextBox80V.Text = ""
TextBox80W.Text = ""
TextBox80X.Text = ""
TextBox80Y.Text = ""
TextBox80Z.Text = ""
TextBox80AA.Text = ""
TextBox80AB.Text = ""
TextBox80AC.Text = ""
TextBox80AD.Text = ""
TextBox81.Text = ""
TextBox81B.Text = ""
TextBox81C.Text = ""
TextBox81D.Text = ""
TextBox81E.Text = ""
TextBox81F.Text = ""
TextBox81G.Text = ""
TextBox81H.Text = ""
TextBox81I.Text = ""
TextBox81J.Text = ""
TextBox81K.Text = ""
TextBox81L.Text = ""
TextBox81M.Text = ""
TextBox81N.Text = ""
TextBox81O.Text = ""
TextBox81P.Text = ""
TextBox81Q.Text = ""
TextBox81R.Text = ""
TextBox81S.Text = ""
TextBox81T.Text = ""
TextBox81U.Text = ""
TextBox81V.Text = ""
TextBox81W.Text = ""
TextBox81X.Text = ""
TextBox81Y.Text = ""
TextBox81Z.Text = ""
TextBox81AA.Text = ""
TextBox81AB.Text = ""
TextBox81AC.Text = ""
TextBox81AD.Text = ""
TextBox82.Text = ""
TextBox82B.Text = ""
TextBox82C.Text = ""
TextBox82D.Text = ""
TextBox82E.Text = ""
TextBox82F.Text = ""
TextBox82G.Text = ""
TextBox82H.Text = ""
TextBox82I.Text = ""
TextBox82J.Text = ""
TextBox82K.Text = ""
TextBox82L.Text = ""
TextBox82M.Text = ""
TextBox82N.Text = ""
TextBox82O.Text = ""
TextBox82P.Text = ""
TextBox82Q.Text = ""
TextBox82R.Text = ""
TextBox82S.Text = ""
TextBox82T.Text = ""
TextBox82U.Text = ""
TextBox82V.Text = ""
TextBox82W.Text = ""
TextBox82X.Text = ""
TextBox82Y.Text = ""
TextBox82Z.Text = ""
TextBox82AA.Text = ""
TextBox82AB.Text = ""
TextBox82AC.Text = ""
TextBox82AD.Text = ""
TextBox83.Text = ""
TextBox83B.Text = ""
TextBox83C.Text = ""
TextBox83D.Text = ""
TextBox83E.Text = ""
TextBox83F.Text = ""
TextBox83G.Text = ""
TextBox83H.Text = ""
TextBox83I.Text = ""
TextBox83J.Text = ""
TextBox83K.Text = ""
TextBox83L.Text = ""
TextBox83M.Text = ""
TextBox83N.Text = ""
TextBox83O.Text = ""
TextBox83P.Text = ""
TextBox83Q.Text = ""
TextBox83R.Text = ""
TextBox83S.Text = ""
TextBox83T.Text = ""
TextBox83U.Text = ""
TextBox83V.Text = ""
TextBox83W.Text = ""
TextBox83X.Text = ""
TextBox83Y.Text = ""
TextBox83Z.Text = ""
TextBox83AA.Text = ""
TextBox83AB.Text = ""
TextBox83AC.Text = ""
TextBox83AD.Text = ""
TextBox84.Text = ""
TextBox84B.Text = ""
TextBox84C.Text = ""
TextBox84D.Text = ""
TextBox84E.Text = ""
TextBox84F.Text = ""
TextBox84G.Text = ""
TextBox84H.Text = ""
TextBox84I.Text = ""
TextBox84J.Text = ""
TextBox84K.Text = ""
TextBox84L.Text = ""
TextBox84M.Text = ""
TextBox84N.Text = ""
TextBox84O.Text = ""
TextBox84P.Text = ""
TextBox84Q.Text = ""
TextBox84R.Text = ""
TextBox84S.Text = ""
TextBox84T.Text = ""
TextBox84U.Text = ""
TextBox84V.Text = ""
TextBox84W.Text = ""
TextBox84X.Text = ""
TextBox84Y.Text = ""
TextBox84Z.Text = ""
TextBox84AA.Text = ""
TextBox84AB.Text = ""
TextBox84AC.Text = ""
TextBox84AD.Text = ""
TextBox85.Text = ""
TextBox85B.Text = ""
TextBox85C.Text = ""
TextBox85D.Text = ""
TextBox85E.Text = ""
TextBox85F.Text = ""
TextBox85G.Text = ""
TextBox85H.Text = ""
TextBox85I.Text = ""
TextBox85J.Text = ""
TextBox85K.Text = ""
TextBox85L.Text = ""
TextBox85M.Text = ""
TextBox85N.Text = ""
TextBox85O.Text = ""
TextBox85P.Text = ""
TextBox85Q.Text = ""
TextBox85R.Text = ""
TextBox85S.Text = ""
TextBox85T.Text = ""
TextBox85U.Text = ""
TextBox85V.Text = ""
TextBox85W.Text = ""
TextBox85X.Text = ""
TextBox85Y.Text = ""
TextBox85Z.Text = ""
TextBox85AA.Text = ""
TextBox85AB.Text = ""
TextBox85AC.Text = ""
TextBox85AD.Text = ""
TextBox86.Text = ""
TextBox86B.Text = ""
TextBox86C.Text = ""
TextBox86D.Text = ""
TextBox86E.Text = ""
TextBox86F.Text = ""
TextBox86G.Text = ""
TextBox86H.Text = ""
TextBox86I.Text = ""
TextBox86J.Text = ""
TextBox86K.Text = ""
TextBox86L.Text = ""
TextBox86M.Text = ""
TextBox86N.Text = ""
TextBox86O.Text = ""
TextBox86P.Text = ""
TextBox86Q.Text = ""
TextBox86R.Text = ""
TextBox86S.Text = ""
TextBox86T.Text = ""
TextBox86U.Text = ""
TextBox86V.Text = ""
TextBox86W.Text = ""
TextBox86X.Text = ""
TextBox86Y.Text = ""
TextBox86Z.Text = ""
TextBox86AA.Text = ""
TextBox86AB.Text = ""
TextBox86AC.Text = ""
TextBox86AD.Text = ""
TextBox87.Text = ""
TextBox87B.Text = ""
TextBox87C.Text = ""
TextBox87D.Text = ""
TextBox87E.Text = ""
TextBox87F.Text = ""
TextBox87G.Text = ""
TextBox87H.Text = ""
TextBox87I.Text = ""
TextBox87J.Text = ""
TextBox87K.Text = ""
TextBox87L.Text = ""
TextBox87M.Text = ""
TextBox87N.Text = ""
TextBox87O.Text = ""
TextBox87P.Text = ""
TextBox87Q.Text = ""
TextBox87R.Text = ""
TextBox87S.Text = ""
TextBox87T.Text = ""
TextBox87U.Text = ""
TextBox87V.Text = ""
TextBox87W.Text = ""
TextBox87X.Text = ""
TextBox87Y.Text = ""
TextBox87Z.Text = ""
TextBox87AA.Text = ""
TextBox87AB.Text = ""
TextBox87AC.Text = ""
TextBox87AD.Text = ""
TextBox88.Text = ""
TextBox88B.Text = ""
TextBox88C.Text = ""
TextBox88D.Text = ""
TextBox88E.Text = ""
TextBox88F.Text = ""
TextBox88G.Text = ""
TextBox88H.Text = ""
TextBox88I.Text = ""
TextBox88J.Text = ""
TextBox88K.Text = ""
TextBox88L.Text = ""
TextBox88M.Text = ""
TextBox88N.Text = ""
TextBox88O.Text = ""
TextBox88P.Text = ""
TextBox88Q.Text = ""
TextBox88R.Text = ""
TextBox88S.Text = ""
TextBox88T.Text = ""
TextBox88U.Text = ""
TextBox88V.Text = ""
TextBox88W.Text = ""
TextBox88X.Text = ""
TextBox88Y.Text = ""
TextBox88Z.Text = ""
TextBox88AA.Text = ""
TextBox88AB.Text = ""
TextBox88AC.Text = ""
TextBox88AD.Text = ""
UserForm2.Hide
UserForm1.Show
End Sub

It basicly simple empty all the textboxes and returns to the main menu of my program.
 
Last edited:

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
:eek:

Is that all of your textboxes? Have you tried simply looping through the controls on your userform?
 

Malkavian

New Member
Joined
Jul 22, 2010
Messages
16
Yeah I thought of how great it would be to be able to actually do that... but I didn't find I way to...

I'm having a strange feeling, a mix of :) and :banghead: ...

Can you give me an exemple of how that could be done?
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650

ADVERTISEMENT

Perhaps
Code:
Sub test()
Dim c As Control
    For Each c In UserForm1.Controls
        If c.Name Like "Textbox*" Then c.Text = ""
    Next c
End Sub
 

Malkavian

New Member
Joined
Jul 22, 2010
Messages
16
Perhaps
Code:
Sub test()
Dim c As Control
    For Each c In UserForm1.Controls
        If c.Name Like "Textbox*" Then c.Text = ""
    Next c
End Sub
Hi! You're code is great. I thought of using wildcard caracters before but couldn't find anything about in VBA on google...

The code isn't working as it should however. Here's the button macro :

Private Sub cmdBack_Click()
Dim c As Control
For Each c In UserForm2.Controls
If c.Name = "TextBox*" Then
c.Text = ""
End If
Next c
UserForm2.Hide
UserForm1.Show
End Sub

It never enters the procedure if... VBA doesn't seem to be recognizing the wildcard caracter (*) properly. However, if I replace "TextBox*" by "TextBox1" it goes in and works for that specific TextBox :eek:. So the issue has to be with the *.

Any idea how we could make VBA understand we want to modify all controls that start with TextBox? Maybe by using the left() function?

Thanks a lot for helping me! Greatly appreciated! :)
 
Last edited:

Malkavian

New Member
Joined
Jul 22, 2010
Messages
16

ADVERTISEMENT

(Solved) VBA Macro makes Excel crash... what are the causes to investigate?

Woohoo!! It works perfectly with Left :

Dim c As Control
For Each c In UserForm2.Controls
If Left(c.Name, 7) = "TextBox" Then
c.Text = ""
End If
Next c
UserForm2.Hide
UserForm1.Show


Oh and Excel doesn't seem to be crashing anymore without those 600 lines!

Thanks again VoG! Have a very nice day! :)
 
Last edited:

yytsunamiyy

Well-known Member
Joined
Mar 17, 2008
Messages
963
As you said, your Solution works. However, note the use of the "Like" Operator rather than the "=" Operator in Peters post.

Rich (BB code):
Sub test()
Dim c As Control
    For Each c In UserForm1.Controls
        If c.Name Like "Textbox*" Then c.Text = ""
    Next c
End Sub
 

yytsunamiyy

Well-known Member
Joined
Mar 17, 2008
Messages
963
Yeah I forgot to replace it. It wasn't working with "like" either though.
It wasn't working because it was refering to Userform1 most likely.

this should work just fine:

Code:
Dim c As Control
    For Each c In UserForm2.Controls
        If c.Name Like "TextBox" Then c.Text = ""
    Next c
UserForm2.Hide
UserForm1.Show
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,861
Messages
5,513,834
Members
408,972
Latest member
TDotHanny

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top