2017-11-03 2 views
0

so letzte Nacht alles funktionierte gut und jetzt ist das passiert. Ich bin mir nicht sicher, wo das Problem liegt, alle anderen Makros funktionieren gut und ich habe es auf ein Benutzerformular eingeschränkt, das alle Fehler verursacht. Es ist eine Warehouse-Verwaltungsdatei, an der ich gerade arbeite, und die Funktion zum Hinzufügen eines neuen Eintrags (neues Formular hinzufügen) friert die gesamte Datei ein.Dieses VBA-Makro zerstört meine Datei und weiß nicht, warum

main sheet img

add line img

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 

Code für UserForm2:

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 

Ich weiß, ihr eine Menge Code, aber seine mich verrückt fahren, ich bin auch ein bisschen wie ein Neuling so krank Notwendigkeit ein bisschen Hilfe. danke

+0

setzen Sie Breakpoints auf den Zeilen, die das Problem verursachen könnte. –

+0

Wissen Sie, wie [Debug-Code] (http://www.cpearson.com/excel/DebuggingVBA.aspx)? –

+0

Sie speichern den globalen Status, ohne es zu merken, indem Sie die Standardinstanz * von userforms verwenden. Wenn Sie mehr über den fortgeschrittenen, objektorientierten Umgang mit Benutzerformularen/Dialogen erfahren möchten, [lesen Sie diesen Artikel] (https://rubberduckvba.wordpress.com/2017/10/25/userform1-show/) (Disclaimer: Ich schrieb es). –

Antwort

0

woow! Ich habe das Problem gefunden, ich habe "nicht genug RAM" Probleme von diesem Code bekommen, nur um das Problem zu finden war in der Zeile einfügen.

von diesem

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

dieser

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

Wunder, warum der Debugger diese nie erwischt? wusste nicht die "gesamte Zeile" soo viel

Verwandte Themen