El código para obtener la última fila
Private Sub CommandButton1_Click() 'GUARDAR
'controla si hay datos en la lista2
If ListBox2.ListCount = 0 Then
MsgBox "No hay datos para guardar"
Exit Sub
End If
'controla datos de proveedor en adelante
Dim validarfecha As Boolean
If ComboBox3 = "" Then
MsgBox "Introduzca el nombre del PROVEEDOR", , "ERROR"
ComboBox3.SetFocus
Exit Sub
End If
If TextBox6 = "" Then
MsgBox "Introduzca la FECHA DE RECEPCIÓN", , "ERROR"
TextBox6.SetFocus
Exit Sub
End If
validarfecha = IsDate(TextBox6.Value) 'fecha rec
If validarfecha = False Then
MsgBox "Introduzca FECHA DE RECEPCIÓN en formato dd/mm/aaaa", , "ERROR"
TextBox6.SetFocus
Exit Sub
End If
If TextBox7 = "" Then 'nro de fact
MsgBox "Introduzca NRO.DE FACTURA del PROVEEDOR", , "ERROR"
TextBox7.SetFocus
Exit Sub
End If
'Valide que se capture la fecha de vencimiento
If TextBox9 = "" Then
MsgBox "Introduzca la FECHA DE VTO.", , "ERROR"
TextBox9.SetFocus
Exit Sub
End If
'Valida que el dato introducido corresponda a una fecha
validarfecha = IsDate(TextBox9.Value) 'fecha VTO
If validarfecha = False Then
MsgBox "Introduzca FECHA DE VTO. en formato dd/mm/aaaa", , "ERROR"
TextBox9.SetFocus
Exit Sub
End If
'******************************************
'Guarda Entrada Material
Dim i As Integer
Dim j As Integer
Dim final As Integer 'nro de fila
Dim ante As Double, actual As Double, canti As Double 'cantidad anterior,esta entrada, cant actual
Dim totante As Double, totactual As Double, total As Double
'For i = 1 To 30000
'If Hoja2.Cells(i, 1) = "" Then 'hoja ENTRADAS
' final = i
' Exit For
'End If
'Next
final = Hoja2.Range("A" & Rows.Count).End(xlUp).Row + 1
'Desproteger la hoja para registro de informacion
Hoja2.Unprotect Password = "1717171"
Hoja6.Unprotect Password = "1717171"
'se recorre el listbox2
For i = 0 To Uf_EntradaMaterial.ListBox2.ListCount - 1
Hoja2.Cells(final, 1) = Uf_EntradaMaterial.ListBox2.List(i, 1) 'cod
Hoja2.Cells(final, 2) = Uf_EntradaMaterial.ListBox2.List(i, 2) 'nbre
Hoja2.Cells(final, 3) = Uf_EntradaMaterial.ListBox2.List(i, 0) 'cant
Hoja2.Cells(final, 4) = Uf_EntradaMaterial.ComboBox3 'prov
Hoja2.Cells(final, 5) = CDate(Uf_EntradaMaterial.TextBox6) 'fec rec
Hoja2.Cells(final, 6) = Uf_EntradaMaterial.TextBox7.Value 'nro fact
Hoja2.Cells(final, 7) = CDate(Uf_EntradaMaterial.TextBox9) 'fec vto
If Uf_EntradaMaterial.ListBox2.List(i, 3) <> "" Then
Hoja2.Cells(final, 9) = CDbl(Uf_EntradaMaterial.ListBox2.List(i, 3)) 'precio indiv.
Hoja2.Cells(final, 8) = Round(CDbl(ListBox2.List(i, 0)) * CDbl(ListBox2.List(i, 3)), 2) 'Valor total
Hoja2.Cells(final, 10) = Uf_EntradaMaterial.TextBox11
End If
'se actualiza la cantidad para este producto
For j = 1 To 30000
If Hoja6.Cells(j, 1) = Hoja2.Cells(final, 1) Then
ante = Hoja6.Cells(j, 4)
totante = Hoja6.Cells(j, 6)
actual = CDbl(Uf_EntradaMaterial.ListBox2.List(i, 0))
totactual = CDbl(Uf_EntradaMaterial.ListBox2.List(i, 3)) * actual
canti = CDbl(Uf_EntradaMaterial.ListBox2.List(i, 0)) + ante
total = Round((totante + totactual) / canti, 2)
Hoja6.Cells(j, 4) = canti
Hoja6.Cells(j, 5) = total
Exit For
End If
Next
'incremento la fila para pasar otro producto
final = final + 1
Next i
'Proteger la hoja entradas y saldo
'Hoja2.Protect Password = "1717171"
'Hoja6.Protect Password = "1717171"
'cierra el UF de Entrada y este (15)
Unload Me
Unload Uf_EntradaMaterial
End Sub
'***********************************
El código para obtener el total:
Private Sub CommandButton3_Click()
'controla que textbox2 sea numérico
If Not IsNumeric(TextBox2) Then
MsgBox "Introduzca valor numérico en campo CANTIDAD.", , "ERROR"
TextBox2.SetFocus
Exit Sub
End If
If Not IsNumeric(TextBox10) Then
MsgBox "Introduzca valor numérico en campo PRECIO.", , "ERROR"
TextBox10.SetFocus
Exit Sub
End If
'Controla que campo cantidad sea > 0
If TextBox2 = 0 Or TextBox2 = "" Then
MsgBox "Introduzca valor mayor a CERO en campo CANTIDAD.", , "ERROR"
TextBox2.SetFocus
Exit Sub
End If
'Controla que campo precio sea > 0
If TextBox10 = 0 Or TextBox10 = "" Then
MsgBox "Introduzca valor mayor a CERO en campo PRECIO.", , "ERROR"
TextBox10.SetFocus
Exit Sub
End If
'Controla los duplicados
ControlItem
If ComboBox1 <> "" And TextBox2 <> "" Then
ListBox2.AddItem TextBox2.Value
ListBox2.List(ListBox2.ListCount - 1, 1) = ComboBox1.Value
ListBox2.List(ListBox2.ListCount - 1, 2) = ComboBox4
If TextBox10 <> "" Then
ListBox2.List(ListBox2.ListCount - 1, 3) = CDbl(TextBox10) * CDbl(TextBox2)
End If
ComboBox1.ListIndex = -1
ComboBox4.ListIndex = -1
TextBox2 = "": TextBox10 = ""
End If
ComboBox1.SetFocus
End Sub
.
'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias
.
Avísame cualquier duda
.