这个 VBA 宏正在破坏我的文件并且不知道为什么

This VBA Macro Is Destroying My File and Dont Know Why

所以昨晚一切正常,现在正在发生这种情况。不确定问题出在哪里,所有其他宏都可以正常工作,我已将其缩小到一个导致所有错误的用户表单。它是我正在处理的仓库管理文件,添加新条目功能(添加新行表格)正在冻结整个文件。

 Sub addline()
' Adds line to top row, currently row 12

   If UserForm2.TextBox3.Text = "" Then
   UserForm2.TextBox3.Text = "Today"
   End If
   UserForm2.Show
    'form2  does the rest of the code, this part works fine
End Sub

用户表单 2 的代码:

Dim strdate As String

Private Sub CommandButton1_Click()
   Application.ScreenUpdating = False

   If Not TextBox1.Text = "" Then
       If Not TextBox2.Text = "" Then
           If Not TextBox3.Text = "" Then

               Sheets("Main").Rows(12).Select
               Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
               Range("B12").Value = False
               Range("C12").Value = TextBox1.Text
               Range("D12").Value = TextBox2.Text
               'makeing the vlookup
               Range("E12").FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-2],rhconv,5,False),""#ERROR"")"
               'adding the date tag
               Range("f12").NumberFormat = "@"
               If TextBox3.Text = "Today" Then
                   strdate = Format(Now(), "mmm dd , yyyy")
                   Range("F12").Value = strdate
               Else  ' else just add the date provided
                   Range("F12").Value = TextBox3.Text
               End If

            UserForm2.Hide
            Range("e12").Select
            If Selection.Value = "#ERROR" Then

                ' this is for the vlookup, if theres no match let the user know

                MsgBox "Line Match Not Found. Please add a match into the system or delete 
                the line and start again."
               Else
                   TextBox1.Text = ""
                   TextBox2.Text = ""
                   TextBox3.Text = "Today"
               End If

               'not sure why but theres a mistake somewhere posting C12 to A12 and G12 when this code works :P
               Range("a12").Value = ""
               Range("g12").Value = ""

           Else
               ' if not everything filled dont let the user move on

               MsgBox "Please fill in all fields before Sumbitting, or Cancel"
           End If
       Else
           MsgBox "Please fill in all fields before Sumbitting, or Cancel"
       End If
   Else
       MsgBox "Please fill in all fields before Sumbitting, or Cancel"
   End If

Application.ScreenUpdating = True

End Sub


Private Sub CommandButton2_Click()
      ' cancel button, works fine i thing the error is in the submit button above
    UserForm2.Hide
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox3.Text = ""
End Sub

我知道它有很多代码,但它让我抓狂,而且我还是个新手,所以我需要一些帮助。谢谢

呜呜呜!我发现了这个问题,我一直从这段代码中得到 "not enough ram" 个问题,只是为了发现问题出在插入行中。

由此

Sheets("Main").Rows(12).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

至此

 Sheets("Main").Range("B12").Entirerow.Insert

想知道为什么调试器从来没有捕获到这个? 不太了解"Entire Row"