Private Sub CommandButtonCapturar_Click()
Dim r As Range
Dim i As Integer
Dim RowCount As Long
Dim LastRow As Long
Dim Cell As Range
LastRow = Range("A" & Rows.Count).End(xlUp).Row
' Here I reduce inventory in accordance with 1er element.
For i = 2 To LastRow
Set Cell = Cells(i, "A")
With Cell
' Aqui resto o sumo a inventario de acuerdo al 1er elemento.
Select Case True
Case .Value = ComboBox1.Value And OptionButton1
.Offset(0, 1) = .Offset(0, 1) + CBcant1.Value
Case .Value = ComboBox1.Value And OptionButton2
.Offset(0, 1) = .Offset(0, 1) - CBcant1.Value
End Select
' Aqui resto o sumo a inventario de acuerdo al 2do elemento.
Select Case True
Case .Value = ComboBox2.Value And OptionButton1
.Offset(0, 1) = .Offset(0, 1) + CBcant2.Value
Case .Value = ComboBox2.Value And OptionButton2
.Offset(0, 1) = .Offset(0, 1) - CBcant2.Value
End Select
' Aqui resto o sumo a inventario de acuerdo al 3er elemento.
Select Case True
Case .Value = ComboBox3.Value And OptionButton1
.Offset(0, 1) = .Offset(0, 1) + CBcant3.Value
Case .Value = ComboBox3.Value And OptionButton2
.Offset(0, 1) = .Offset(0, 1) - CBcant3.Value
End Select
' Aqui resto o sumo a inventario de acuerdo al 4to elemento.
Select Case True
Case .Value = ComboBox4.Value And OptionButton1
.Offset(0, 1) = .Offset(0, 1) + CBcant4.Value
Case .Value = ComboBox4.Value And OptionButton2
.Offset(0, 1) = .Offset(0, 1) - CBcant4.Value
End Select
' Aqui resto o sumo a inventario de acuerdo al 5to elemento.
Select Case True
Case .Value = ComboBox5.Value And OptionButton1
.Offset(0, 1) = .Offset(0, 1) + CBcant5.Value
Case .Value = ComboBox5.Value And OptionButton2
.Offset(0, 1) = .Offset(0, 1) - CBcant5.Value
End Select
End With
Next i
' Historial
RowCount = Worksheets("Hoja3").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Hoja3").Range("A1")
.Offset(RowCount, 0).Value = TextBox6.Value
.Offset(RowCount, 1).Value = ComboBox1.Value
.Offset(RowCount, 2).Value = TextBox12.Value
If OptionButton1 = True Then
.Offset(RowCount, 3).Value = "entrada"
ElseIf OptionButton2 = True Then
.Offset(RowCount, 3).Value = "salida"
End If
If CBcant2.Value = "" Then
Exit Sub
Else
RowCount = RowCount + 1
.Offset(RowCount, 0).Value = TextBox6.Value
.Offset(RowCount, 1).Value = ComboBox2.Value
.Offset(RowCount, 2).Value = TextBox12.Value
If OptionButton1 = True Then
.Offset(RowCount, 3).Value = "entrada"
Else
If OptionButton2 = True Then
.Offset(RowCount, 3).Value = "salida"
End If
End If
End If
If CBcant3.Value = "" Then
Exit Sub
Else
RowCount = RowCount + 1
.Offset(RowCount, 0).Value = TextBox6.Value
.Offset(RowCount, 1).Value = ComboBox3.Value
.Offset(RowCount, 2).Value = TextBox12.Value
If OptionButton1 = True Then
.Offset(RowCount, 3).Value = "entrada"
Else
If OptionButton2 = True Then
.Offset(RowCount, 3).Value = "salida"
End If
End If
End If
If CBcant4.Value = "" Then
Exit Sub
Else
RowCount = RowCount + 1
.Offset(RowCount, 0).Value = TextBox6.Value
.Offset(RowCount, 1).Value = ComboBox4.Value
.Offset(RowCount, 2).Value = TextBox12.Value
If OptionButton1 = True Then
.Offset(RowCount, 3).Value = "entrada"
Else
If OptionButton2 = True Then
.Offset(RowCount, 3).Value = "salida"
End If
End If
End If
If CBcant5.Value = "" Then
Exit Sub
Else
RowCount = RowCount + 1
.Offset(RowCount, 0).Value = TextBox6.Value
.Offset(RowCount, 1).Value = ComboBox5.Value
.Offset(RowCount, 2).Value = TextBox12.Value
If OptionButton1 = True Then
.Offset(RowCount, 3).Value = "entrada"
Else
If OptionButton2 = True Then
.Offset(RowCount, 3).Value = "salida"
End If
End If
End If
End With
' Clear the form
For Each ctl In Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
Else
If TypeName(ctl) = "CheckBox" Then
tl.Value = False
End If
End If
Next
End Sub
Bookmarks