Macro para eliminar de ListBox y hojas marca error
publicado
Hoja amigos, les traigo a ustedes este error que me marca una macro, cabe decir que algunas macros las encontré en este foro y las adapte a mis necesidades. Les platico.
la siguiente macro la tengo en un botón, el cual al dar clic llama a un userform
Private Sub CommandButton6_Click()
EliminarFilas2.Show
End Sub
en ese userform hay que poner una contraseña para poder eliminar
Private Sub CommandButton1_Click()
Dim resp As Integer
resp = 3313
If TextBox1 = 3313 Then
Unload Me
'Tu procedimiento aquí
Call Busqueda_Resguardo.eliminarProducto
Else
MsgBox ("La clave ingresada es incorrecta"), vbInformation, "AVISO"
TextBox1 = Clear
TextBox1.SetFocus
End If
End Sub
al dar clic debería ,eliminar del listbox y hojas pero me arroja un error.
Sub eliminarProducto()
'Borrar del ListBox y de las hojas
Dim sino As String
sino = MsgBox("Estás seguro de Eliminar el Articulo seleccionado?", vbYesNo + vbQuestion, "CONFIRMA")
If sino <> vbYes Then Exit Sub
Dim fila As Integer
Dim Final As Integer
Dim Cantidad As Integer
''''AQUI REGISTRO EL CORRELATIVO FINAL PROCESADO
Dim NombreHoja As String
NombreHoja = "Inventario"
'Buscamos la última fila
'EN EL SIGUIENTE ME ESTOY REFIRIENDO A LA HOJA SEGUN EL SECTOR
fila = 2
Do While ThisWorkbook.Sheets(NombreHoja).Cells(fila, 1) <> ""
fila = fila + 1
Loop
Final = fila
'CON ESTE CODIGO ESTARE RESTANDO "1" AL FOLIO EN CASO SE REGRESE A LA VENTANA ANTERIOR
For fila = 2 To Final
If ThisWorkbook.Sheets(NombreHoja).Cells(fila, 1) = ListBox1.Column(0) Then 'CORRESPONDE A LA COLUMNA "A"
ThisWorkbook.Sheets(NombreHoja).Cells(fila, 8) = ThisWorkbook.Sheets(NombreHoja).Cells(fila, 7) - Val(ListBox1.Column(5))
Exit For
End If
Next
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Dim row_LB&
With ListBox1
row_LB = .ListIndex
If row_LB = -1 Then Exit Sub
.RemoveItem row_LB
.ListIndex = -1
End With
With Sheets("Salidas")
.Range("a2:n2").Offset(row_LB).Delete xlShiftUp
End With
With Sheets("Temporal")
.Range("a2:n2").Offset(row_LB).Delete xlShiftUp
End With
With Sheets("Resguardo")
.Range("a2:i2").Offset(row_LB).Delete xlShiftUp
End With
With Sheets("Stock")
.Range("a2:n2").Offset(row_LB).Delete xlShiftUp
End With
MsgBox "Selección eliminada"
End Sub
de esta ultima macro me corre solo hasta aquí:
sino = MsgBox("Estás seguro de Eliminar el Articulo seleccionado?", vbYesNo + vbQuestion, "CONFIRMA")
If sino <> vbYes Then Exit Sub
y es justo ahí es donde salta error pero en la segunda macro que coloque en esta parte
Call Busqueda_Resguardo.eliminarProducto
Se que es mucho rollo pero espero y me ayuden
Featured Replies
Archivado
Este tema está ahora archivado y está cerrado a más respuestas.
Hoja amigos, les traigo a ustedes este error que me marca una macro, cabe decir que algunas macros las encontré en este foro y las adapte a mis necesidades. Les platico.
la siguiente macro la tengo en un botón, el cual al dar clic llama a un userform
Private Sub CommandButton6_Click() EliminarFilas2.Show End Sub
en ese userform hay que poner una contraseña para poder eliminar
Private Sub CommandButton1_Click() Dim resp As Integer resp = 3313 If TextBox1 = 3313 Then Unload Me 'Tu procedimiento aquí Call Busqueda_Resguardo.eliminarProducto Else MsgBox ("La clave ingresada es incorrecta"), vbInformation, "AVISO" TextBox1 = Clear TextBox1.SetFocus End If End Sub
al dar clic debería ,eliminar del listbox y hojas pero me arroja un error.
Sub eliminarProducto() 'Borrar del ListBox y de las hojas Dim sino As String sino = MsgBox("Estás seguro de Eliminar el Articulo seleccionado?", vbYesNo + vbQuestion, "CONFIRMA") If sino <> vbYes Then Exit Sub Dim fila As Integer Dim Final As Integer Dim Cantidad As Integer ''''AQUI REGISTRO EL CORRELATIVO FINAL PROCESADO Dim NombreHoja As String NombreHoja = "Inventario" 'Buscamos la última fila 'EN EL SIGUIENTE ME ESTOY REFIRIENDO A LA HOJA SEGUN EL SECTOR fila = 2 Do While ThisWorkbook.Sheets(NombreHoja).Cells(fila, 1) <> "" fila = fila + 1 Loop Final = fila 'CON ESTE CODIGO ESTARE RESTANDO "1" AL FOLIO EN CASO SE REGRESE A LA VENTANA ANTERIOR For fila = 2 To Final If ThisWorkbook.Sheets(NombreHoja).Cells(fila, 1) = ListBox1.Column(0) Then 'CORRESPONDE A LA COLUMNA "A" ThisWorkbook.Sheets(NombreHoja).Cells(fila, 8) = ThisWorkbook.Sheets(NombreHoja).Cells(fila, 7) - Val(ListBox1.Column(5)) Exit For End If Next '///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Dim row_LB& With ListBox1 row_LB = .ListIndex If row_LB = -1 Then Exit Sub .RemoveItem row_LB .ListIndex = -1 End With With Sheets("Salidas") .Range("a2:n2").Offset(row_LB).Delete xlShiftUp End With With Sheets("Temporal") .Range("a2:n2").Offset(row_LB).Delete xlShiftUp End With With Sheets("Resguardo") .Range("a2:i2").Offset(row_LB).Delete xlShiftUp End With With Sheets("Stock") .Range("a2:n2").Offset(row_LB).Delete xlShiftUp End With MsgBox "Selección eliminada" End Sub
de esta ultima macro me corre solo hasta aquí:
sino = MsgBox("Estás seguro de Eliminar el Articulo seleccionado?", vbYesNo + vbQuestion, "CONFIRMA") If sino <> vbYes Then Exit Sub
y es justo ahí es donde salta error pero en la segunda macro que coloque en esta parte
Call Busqueda_Resguardo.eliminarProducto
Se que es mucho rollo pero espero y me ayuden