2017-11-03 22 views
0

昨夜はすべてがうまくいきました。問題がどこにあるのかわからない場合は、他のすべてのマクロが正常に動作し、すべてのエラーの原因となっている1つのuserformに絞り込んでいます。私が取り組んでいる倉庫管理ファイルです。新しいエントリ機能を追加すると(新しい行形式を追加すると)、ファイル全体がフリーズしています。 userform2ためこのVBAマクロは私のファイルを破壊していますが、理由は分かりません

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 

コード:

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 

私はコードのその多くを知っているが、その私にナットを駆動するには、また、初心者ので、病気の必要性を少しイム少しの助け。高等学校

+0

問題を引き起こしている可能性のある行にブレークポイントを設定してください。 –

+0

[デバッグコード](http://www.cpearson.com/excel/DebuggingVBA.aspx)を知っていますか? –

+0

userformsの* default instance *を使用して、グローバル状態を認識せずに格納しています。ユーザーフォーム/ダイアログのより高度な、オブジェクト指向の処理について知りたい場合は、[この記事を読む](https://rubberduckvba.wordpress.com/2017/10/25/userform1-show/)(免責事項:私はそれ)。 –

答えて

0

wooow!私は問題を見つけた、私は問題が行の挿入にあったことを見つけるために、このコードから "十分でないRAM"の問題を続けていた。デバッガはこれを捕まえたことがない、なぜこの

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

不思議にこの

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

から

? 多くの場合、「全体行」を知りませんでした。

関連する問題