Object Required Error

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I have a form called "Miter_2_Correc", and I don't know why vba won't let me open it, can someone help me?



Code:

VBA Code:
Private Sub bt_calculate_Click()

    Call CheckEmpty

End Sub


Private Sub CheckEmpty()
   
If Not IsNumeric(tb_x1.Value) Or tb_x1.Text = "" Or Trim(tb_x1.Text) = "" Then
    MsgBox "'X1 Value ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(tb_x2.Value) Or tb_x2.Text = "" Or Trim(tb_x2.Text) = "" Then
    MsgBox "'X2 Value ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(tb_100.Value) Or tb_100.Text = "" Or Trim(tb_100.Text) = "" Then
    MsgBox "'Z = 100 ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(tb_250.Value) Or tb_250.Text = "" Or Trim(tb_250.Text) = "" Then
    MsgBox "'Z = 250 ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(tb_400.Value) Or tb_400.Text = "" Or Trim(tb_400.Text) = "" Then
    MsgBox "'Z = 400 ' está vazio ou contém letras", vbExclamation
   
ElseIf Not IsNumeric(tb_550.Value) Or tb_550.Text = "" Or Trim(tb_550.Text) = "" Then
    MsgBox "'Z = 550 ' está vazio ou contém letras", vbExclamation
   
   
Else

    X1_Axis_Orig = tb_x1.Value
    X2_Axis_Orig = tb_x2.Value
    Z_100_Final = tb_100.Value
    Z_250_Final = tb_250.Value
    Z_400_Final = tb_400.Value
    Z_550_Final = tb_550.Value
    lb_result.Caption = Z_550_Final * 1 - X2_Axis_Orig * 1
    tb_x1.Enabled = False
    tb_x2.Enabled = False
    bt_calculate.Enabled = False
    tb_100.Enabled = False
    tb_250.Enabled = False
    tb_400.Enabled = False
    tb_550.Enabled = False
    bt_next.Enabled = True
    Call ShowTextBox

End If
End Sub


Private Sub bt_next_Click()

    Worksheets("Miter").Select
    Range("B15").Value = Z_550_Final
    Range("F15").Value = Z_250_Final
    Range("D15").Value = Z_400_Final
    Range("I15").Value = Z_100_Final
    Range("K17").Value = X1_Axis_Orig
    Range("K21").Value = X2_Axis_Orig
    Range("X14").Value = Aditional_Info
    Call Correction_E
   
End Sub


Private Sub Correction_E()

If Z_550_Final <= 0 And X2_Axis_Orig <= 0 Then

    If Z_550_Final * 1 - X2_Axis_Orig * 1 <= 30 And Z_550_Final * 1 - X2_Axis_Orig * 1 >= -30 Then
        Call KillEmpty_Miter
        Miter_Complete.Show
       
    ElseIf Z_550_Final * 1 - X2_Axis_Orig * 1 > 30 Or Z_550_Final * 1 - X2_Axis_Orig * 1 < -30 Then
        Unload Me
        Miter_2_Correc.Show
   
    End If
   
   
             
ElseIf Z_550_Final >= 0 And X2_Axis_Orig <= 0 Then

    If Z_550_Final - X2_Axis_Orig * 1 <= 30 And Z_550_Final - X2_Axis_Orig * 1 >= -30 Then
        Call KillEmpty_Miter
        Miter_Complete.Show
       
    ElseIf Z_550_Final - X2_Axis_Orig * 1 > 30 Or Z_550_Final - X2_Axis_Orig * 1 < -30 Then
        Unload Me
        Miter_2_Correc.Show
   
    End If
   
               
ElseIf Z_550_Final >= 0 And X2_Axis_Orig >= 0 Then

    If Z_550_Final - X2_Axis_Orig >= -30 And Z_550_Final - X2_Axis_Orig <= 30 Then
        Call KillEmpty_Miter
        Miter_Complete.Show
       
    ElseIf Z_550_Final - X2_Axis_Orig > 30 Or Z_550_Final - X2_Axis_Orig < -30 Then
        Unload Me
        Miter_2_Correc.Show
       
    End If
         
                 
ElseIf Z_550_Final <= 0 And X2_Axis_Orig >= 0 Then

    If Z_550_Final * 1 - X2_Axis_Orig <= 30 And Z_550_Final * 1 - X2_Axis_Orig >= -30 Then
        Call KillEmpty_Miter
        Miter_Complete.Show
       
    ElseIf Z_550_Final * 1 - X2_Axis_Orig > 30 Or Z_550_Final * 1 - X2_Axis_Orig < -30 Then
        Unload Me
        Miter_2_Correc.Show
       
    End If
             
End If

End Sub


Private Sub bt_ok_Click()

    bt_ok.Enabled = False
    Aditional_Info_A = txt_a.Value
    txt_a.Enabled = False

End Sub


Private Sub ShowTextBox()


If Z_550_Final <= 0 And X2_Axis_Orig <= 0 Then

    If Z_550_Final * 1 - X2_Axis_Orig * 1 <= 30 And Z_550_Final * 1 - X2_Axis_Orig * 1 >= -30 Then
        txt_a.Visible = True
        lb_aditional.Visible = True
        bt_ok.Visible = True
       
    ElseIf Z_550_Final * 1 - X2_Axis_Orig * 1 > 30 Or Z_550_Final * 1 - X2_Axis_Orig * 1 < -30 Then
    End If
   
             
ElseIf Z_550_Final >= 0 And X2_Axis_Orig <= 0 Then

    If Z_550_Final - X2_Axis_Orig * 1 <= 30 And Z_550_Final - X2_Axis_Orig * 1 >= -30 Then
        txt_a.Visible = True
        lb_aditional.Visible = True
        bt_ok.Visible = True
       
    ElseIf Z_550_Final - X2_Axis_Orig * 1 > 30 Or Z_550_Final - X2_Axis_Orig * 1 < -30 Then
    End If
   
               
ElseIf Z_550_Final >= 0 And X2_Axis_Orig >= 0 Then

    If Z_550_Final - X2_Axis_Orig >= -30 And Z_550_Final - X2_Axis_Orig <= 30 Then
        txt_a.Visible = True
        lb_aditional.Visible = True
        bt_ok.Visible = True
       
    ElseIf Z_550_Final - X2_Axis_Orig > 30 Or Z_550_Final - X2_Axis_Orig < -30 Then
    End If
         
         
ElseIf Z_550_Final <= 0 And X2_Axis_Orig >= 0 Then

    If Z_550_Final * 1 - X2_Axis_Orig <= 30 And Z_550_Final * 1 - X2_Axis_Orig >= -30 Then
        txt_a.Visible = True
        lb_aditional.Visible = True
        bt_ok.Visible = True
       
    ElseIf Z_550_Final * 1 - X2_Axis_Orig > 30 And Z_550_Final * 1 - X2_Axis_Orig < -30 Then
    End If
       
End If
End Sub


Private Sub UserForm_Initialize()
   
    txt_a.Visible = False
    lb_aditional.Visible = False
    bt_ok.Visible = False
    bt_next.Enabled = False
   
End Sub


Private Sub FillCells_Miter()

    'Z & Y Before
    ActiveCell.Value = MachineName
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Tec
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Date_Today
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = hour
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Y1_Axis_Orig
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Y2_Axis_Orig
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_100_Orig
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_250_Orig
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_400_Orig
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_550_Orig
    ActiveCell.Offset(0, 1).Select
    Call ColorCells_Miter_1
    ActiveCell.Offset(0, 1).Select

   
    'Z & Y After
    ActiveCell.Value = Y1_Axis_Orig_D
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Y2_Axis_Orig_D
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_100_Orig_D
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_250_Orig_D
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_400_Orig_D
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_550_Orig_D
    ActiveCell.Offset(0, 1).Select
    Call ColorCells_Miter_2
    ActiveCell.Offset(0, 1).Select
   
   
    'Z & X Before
    ActiveCell.Value = X1_Axis_Orig
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = X2_Axis_Orig
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_100_Final
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_250_Final
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_400_Final
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Z_550_Final
    ActiveCell.Offset(0, 1).Select
    Call ColorCells_Miter_3
    ActiveCell.Offset(0, 7).Select
   
   
    'Z & X After
    Call ColorCells_Miter_4
   
    Unload Me
   
End Sub



Public Sub ColorCells_Miter_1()

If ActiveCell.Column = 12 Then

    If Z_550_Orig <= 0 And Y2_Axis_Orig <= 0 Then

        If Z_550_Orig * 1 - Y2_Axis_Orig * 1 <= 30 And Z_550_Orig * 1 - Y2_Axis_Orig * 1 >= -30 * 1 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Orig * 1 - Y2_Axis_Orig * 1 > 30 Or Z_550_Orig * 1 - Y2_Axis_Orig * 1 < -30 * 1 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
   
        End If
   
             
    ElseIf Z_550_Orig >= 0 And Y2_Axis_Orig <= 0 Then

        If Z_550_Orig - Y2_Axis_Orig * 1 <= 30 And Z_550_Orig - Y2_Axis_Orig * 1 >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Orig - Y2_Axis_Orig * 1 > 30 Or Z_550_Orig - Y2_Axis_Orig * 1 < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
   
        End If
   
       
         
    ElseIf Z_550_Orig >= 0 And Y2_Axis_Orig >= 0 Then

        If Z_550_Orig - Y2_Axis_Orig >= -30 And Z_550_Orig - Y2_Axis_Orig <= 30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Orig - Y2_Axis_Orig > 30 Or Z_550_Orig - Y2_Axis_Orig < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
       
        End If
         
         
         
    ElseIf Z_550_Orig <= 0 And Y2_Axis_Orig >= 0 Then

        If Z_550_Orig * 1 - Y2_Axis_Orig <= 30 And Z_550_Orig * 1 - Y2_Axis_Orig >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Orig * 1 - Y2_Axis_Orig > 30 Or Z_550_Orig * 1 - Y2_Axis_Orig < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
       
        End If
         
    End If
     
End If
End Sub



Public Sub ColorCells_Miter_2()

If ActiveCell.Column = 19 Then
     
    If Z_550_Orig_D <= 0 And Y2_Axis_Orig_D <= 0 Then

        If Z_550_Orig_D * 1 - Y2_Axis_Orig_D * 1 <= 30 And Z_550_Orig_D * 1 - Y2_Axis_Orig_D * 1 >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Orig_D * 1 - Y2_Axis_Orig_D * 1 > 30 Or Z_550_Orig_D * 1 - Y2_Axis_Orig_D * 1 < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
   
        End If
   
             
    ElseIf Z_550_Orig_D >= 0 And Y2_Axis_Orig_D <= 0 Then

        If Z_550_Orig_D - Y2_Axis_Orig_D * 1 <= 30 And Z_550_Orig_D - Y2_Axis_Orig_D * 1 >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Orig_D - Y2_Axis_Orig_D * 1 > 30 Or Z_550_Orig_D - Y2_Axis_Orig_D * 1 < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
   
        End If
   
       
         
    ElseIf Z_550_Orig_D >= 0 And Y2_Axis_Orig_D >= 0 Then

        If Z_550_Orig_D - Y2_Axis_Orig_D >= -30 And Z_550_Orig_D - Y2_Axis_Orig_D <= 30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Orig_D - Y2_Axis_Orig_D > 30 Or Z_550_Orig_D - Y2_Axis_Orig_D < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
       
        End If
         
         
         
    ElseIf Z_550_Orig <= 0 And Y2_Axis_Orig >= 0 Then

        If Z_550_Orig_D * 1 - Y2_Axis_Orig_D <= 30 And Z_550_Orig_D * 1 - Y2_Axis_Orig_D >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Orig_D * 1 - Y2_Axis_Orig_D > 30 Or Z_550_Orig_D * 1 - Y2_Axis_Orig_D < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
       
        End If
             
    End If
   
End If
End Sub



Public Sub ColorCells_Miter_3()

If ActiveCell.Column = 26 Then
     
   If Z_550_Final <= 0 And X2_Axis_Orig <= 0 Then

        If Z_550_Final * 1 - X2_Axis_Orig * 1 <= 30 And Z_550_Final * 1 - X2_Axis_Orig * 1 >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Final * 1 - X2_Axis_Orig * 1 > 30 Or Z_550_Final * 1 - X2_Axis_Orig * 1 < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
   
        End If
   
             
    ElseIf Z_550_Final >= 0 And X2_Axis_Orig <= 0 Then

        If Z_550_Final - X2_Axis_Orig * 1 <= 30 And Z_550_Final - X2_Axis_Orig * 1 >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Final - X2_Axis_Orig * 1 > 30 Or Z_550_Final - X2_Axis_Orig * 1 < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
   
        End If
   
       
    ElseIf Z_550_Final >= 0 And X2_Axis_Orig >= 0 Then

        If Z_550_Final - X2_Axis_Orig >= -30 And Z_550_Final - X2_Axis_Orig <= 30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Final - X2_Axis_Orig > 30 Or Z_550_Final - X2_Axis_Orig < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
       
        End If
         
         

    ElseIf Z_550_Final <= 0 And X2_Axis_Orig >= 0 Then

        If Z_550_Final * 1 - X2_Axis_Orig <= 30 And Z_550_Final * 1 - X2_Axis_Orig >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Final * 1 - X2_Axis_Orig > 30 Or Z_550_Final * 1 - X2_Axis_Orig < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
       
        End If
             
    End If
   
End If
End Sub



Public Sub ColorCells_Miter_4()

If ActiveCell.Column = 33 Then
     
   If Z_550_Final_D <= 0 And X2_Axis_Orig_D <= 0 Then

        If Z_550_Final_D * 1 - X2_Axis_Orig_D * 1 <= 30 And Z_550_Final_D * 1 - X2_Axis_Orig_D * 1 >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Final_D * 1 - X2_Axis_Orig_D * 1 > 30 Or Z_550_Final_D * 1 - X2_Axis_Orig_D * 1 < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
   
        End If
   
             
    ElseIf Z_550_Final_D >= 0 And X2_Axis_Orig_D <= 0 Then

        If Z_550_Final_D - X2_Axis_Orig_D * 1 <= 30 And Z_550_Final_D - X2_Axis_Orig_D * 1 >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Final_D - X2_Axis_Orig_D * 1 > 30 Or Z_550_Final_D - X2_Axis_Orig_D * 1 < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
   
        End If
   
       
    ElseIf Z_550_Final_D >= 0 And X2_Axis_Orig_D >= 0 Then

        If Z_550_Final_D - X2_Axis_Orig_D >= -30 And Z_550_Final_D - X2_Axis_Orig_D <= 30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Final_D - X2_Axis_Orig_D > 30 Or Z_550_Final_D - X2_Axis_Orig_D < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
       
        End If
         
               
    ElseIf Z_550_Final_D <= 0 And X2_Axis_Orig_D >= 0 Then

        If Z_550_Final_D * 1 - X2_Axis_Orig_D <= 30 And Z_550_Final_D * 1 - X2_Axis_Orig_D >= -30 Then
            ActiveCell.Interior.ColorIndex = 4
            ActiveCell.Font.Color = vbBlack
            ActiveCell.Value = "Não Precisa de Correção"
       
        ElseIf Z_550_Final_D * 1 - X2_Axis_Orig_D > 30 Or Z_550_Final_D * 1 - X2_Axis_Orig_D < -30 Then
            ActiveCell.Interior.ColorIndex = 3
            ActiveCell.Value = "Correção Necessária"
       
        End If
         
    End If
   
End If
End Sub


Public Sub KillEmpty_Miter()

    Dim k As Long

    ActiveWorkbook.Sheets("Miter_Registers").Select

    Range("B4").Select
   
    k = ActiveSheet.Range("B4", ActiveSheet.Range("B4").End(xlDown)).Rows.Count
   
    If ActiveCell.Value = "" Then
        Call FillCells_Miter
   
    ElseIf ActiveCell.Value <> "" Then
        Do Until ActiveCell.Value = ""
            ActiveCell.Offset(1, 0).Select
        Loop
        Call FillCells_Miter
       
    End If
End Sub




Capturar22.JPG
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
If a test VBA procedure with only the codeline to open this specific UserForm well works​
so that just means you must review the condition 'logic' to open it in your main procedure …​
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,005
Members
449,092
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top