I have this code in which I do some checking to delete items in a table according to their numeration. When debugging the code whenever it reaches the critical line (shown below) it jumps to the respective Excel Objects code of that sheet (shown even lower). I already tested positioning it in different places across the code and using Application.Enableevents = false
but it didn't work.
Any suggestions?
First Code:
Sub deleta_linhas()
Dim linha As Integer, coluna As Integer
Dim n_item As Integer, n_prod As Integer
Dim soma As Integer, linha_selecionada As Integer
linha_selecionada = ActiveCell.Row
Dim linha_atual(1 To 2) As Integer, next_line(1 To 2) As Integer, line_before(1 To 2) As Integer
Dim i As Integer
i = 0
Dim novos_numeros As String
' Condição 1 em que há apenas 1.1 e mais nada
If IsEmpty(Cells(36, 1)) = True Then
ActiveCell.EntireRow.Delete
Range("B5").Value = 1
Range("B6").Value = 1
Range("B7").Value = 0
Range("B8").Value = 35
Else
' Condição 2 em que há 1.1, 1.2 e mais ou 1.1, 2.1 e mais
linha_atual(1) = Mid(Cells(linha_selecionada, 1), 1, 1)
linha_atual(2) = Mid(Cells(linha_selecionada, 1), 5, 1)
next_line(1) = Mid(Cells(linha_selecionada + 1, 1), 1, 1)
next_line(2) = Mid(Cells(linha_selecionada + 1, 1), 5, 1)
line_before(1) = Mid(Cells(linha_selecionada - 1, 1), 1, 1)
line_before(2) = Mid(Cells(linha_selecionada - 1, 1), 5, 1)
If linha_atual(1) = next_line(1) = False And linha_atual(2) = next_line(2) Then
Selection.EntireRow.Delete '(THIS IS WHERE IT JUMPS TO EXCEL OBJECTS)
Range("B8").Value = Range("B8").Value - 1
Range("B5").Value = Range("B5").Value - 1
While IsEmpty(Cells(linha_selecionada + i, 1)) = False
n_item = Mid(Cells(linha_selecionada + 1, 1), 1, 1) - 1
novos_numeros = n_item & " . 1"
Cells(linha_selecionada + 1, 1).Value = novos_numeros
i = i + 1
Wend
End If
End If
linha = 36
coluna = 9
soma = 0
Selection.EntireRow.Delete
While IsEmpty(Cells(linha, coluna)) = False
soma = soma + Cells(linha, coluna).Value
linha = linha + 1
Wend
linha = linha + 1
Cells(linha, coluna).Value = soma
End Sub
Code in the Excel Objects (mostly of combobox buttons)
Private Sub ComboBox1_Change()
If ComboBox1.Value = "Fabricação" Then
Rows("41:52").Select
Selection.EntireRow.Hidden = True
Range("B28").Select
Range("B11").Value = "Fabricação"
End If
If ComboBox1.Value = "Nacionalização" Then
Rows("41:52").Select
Selection.EntireRow.Hidden = False
Range("B28").Select
Range("B11").Value = "Nacionalização"
End If
If ComboBox1.Value = "Projeto" Then
Rows("41:52").Select
Selection.EntireRow.Hidden = False
Range("B28").Select
Range("B11").Value = "Projeto"
End If
If ComboBox1.Value = "Manutenção" Then
Rows("41:52").Select
Selection.EntireRow.Hidden = False
Range("B28").Select
Range("B11").Value = "Manutenção"
End If
If ComboBox1.Value = "Industrialização" Then
Rows("41:52").Select
Selection.EntireRow.Hidden = False
Range("B28").Select
Range("B11").Value = "Industrialização"
End If
End Sub
' Lógicas dos tratamentos
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then
Range("B10").Value = "Tempera"
End If
End Sub
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
Range("B10").Value = "Nitretação"
End If
End Sub
Private Sub OptionButton3_Click()
If OptionButton3.Value = True Then
Range("B10").Value = "Cementação"
End If
End Sub
Private Sub OptionButton4_Click()
If OptionButton4.Value = True Then
Range("B10").Value = "---"
End If
End Sub
' FIM