Hola Leonielhou,
He leido el tema del enlace y noto que el problema del usuario fue resuelto a traves del alimpieza de un ListBox, pero en mi caso, esta parte del codigo no esta siendo accionada a traves de un ListBox.
El codigo corresponde a un formulario comun, que adiciona nuevos datos a una tabla dinamica ya definida, sin necesiadad de ningun lisbox. solo textbox. A continuacion dejo el codigo creado dentro del modulo para esta parte, asi como una vista del formulario.
Gracias por la ayuda que me puedas brindar Leonielhou.
Sub IngresarNuevoMaterial()
With frmMateriales
If .txtMaterial = "" Then
MsgBox "Ingrese un Nombre de Material.", vbInformation, "Atención"
.txtMaterial.SetFocus
Exit Sub
End If
Dim BM As Range
Dim NombreMaterial As String
Dim siexiste As Long
Set BM = Hoja5.ListObjects("MATERIALES").ListColumns(2).DataBodyRange
NombreMaterial = .txtMaterial.Value
siexiste = Application.WorksheetFunction.CountIf(BM, NombreMaterial)
If siexiste <> 0 Then
MsgBox "El Material ingresado ya existe.", vbInformation, "Error"
.txtMaterial.Value = ""
.txtMaterial.SetFocus
Exit Sub
End If
If .txtUMaterial = "" Then
MsgBox "Ingrese una Unidad de medida del material.", vbInformation, "Atención"
.txtUMaterial.SetFocus
Exit Sub
End If
If .txtPMaterial = "" Then
MsgBox "Ingrese un Costo del material.", vbInformation, "Atención"
.txtPMaterial.SetFocus
Exit Sub
End If
If .txtProvedor = "" Then
MsgBox "Ingrese un provedor de referencia del material.", vbInformation, "Atención"
.txtProvedor.SetFocus
Exit Sub
End If
If .txtFecha = "" Then
MsgBox "Ingrese una fecha de referencia de cotización del material.", vbInformation, "Atención"
.txtFecha.SetFocus
Exit Sub
End If
'\\crear nueva celda
Dim SiguienteCelda As Object
Sheets("MATERIALES").Unprotect Password:="xxxx"
If (Hoja5.ListObjects("MATERIALES").DataBodyRange.Rows.Count = 1) \_
And (Hoja5.ListObjects("MATERIALES").ListRows(1).Range.Cells(1).Value = "") Then
Set SiguienteCelda = Hoja1.Range("A13")
Else
Set SiguienteCelda = Hoja5.ListObjects("MATERIALES").ListRows.Add.Range.Cells(1)
End If
'\\llenar la base de materiales
With SiguienteCelda
Dim UltimoRegistro As Integer
UltimoRegistro = Hoja5.Range("H1").Value
.Value = CStr("MT" & UltimoRegistro + 1)
.Offset(0, 1).Value = frmMateriales.txtMaterial.Value
.Offset(0, 2).Value = frmMateriales.txtUMaterial.Value
.Offset(0, 6).Value = frmMateriales.txtPMaterial.Value
.Offset(0, 12).Value = frmMateriales.txtProvedor.Value
.Offset(0, 7).Value = frmMateriales.txtFecha.Value
.Offset(0, 9).Value = frmMateriales.txtFecha.Value
.Offset(0, 11).Value = frmMateriales.txtFecha.Value
End With
Unload frmMateriales
'\\incremento del ultimo registro
Hoja5.Range("H1").Value = Hoja5.Range("H1").Value + 1
Sheets("MATERIALES").Protect Password:="xxxx", AllowInsertingRows:=True, AllowSorting:=True, \_
AllowFiltering:=True, AllowDeletingRows:=True
End With
End Sub

