Eliminar datos de ListBox y Hojas excel
Tengo la siguiente instrucción para eliminar datos cargados en un ListBox y 3 hojas excel, funciona a media ya que si puedo eliminar el dato seleccionado en el ListBox y en dos de tres hojas donde se cargan los datos. La hoja donde no se eliminan los datos es "Salidas". Lo mas raro que tienen las mismas instrucciones y no lo elimina de la hoja salida. Espero la ayuda de algún experto.
Private Sub CommandButton5_Click()
'Eliminar del ListBox y de las hojas
Dim row_LB&
Dim SiNo As String
Dim NewRow As Integer
Dim varRow As Integer
Dim a
SiNo = MsgBox("Estás seguro de Eliminar el Articulo seleccionado?", vbYesNo + vbQuestion, "CONFIRMA")
If SiNo <> vbYes Then Exit Sub
With ListBox1
row_LB = .ListIndex
If row_LB = -1 Then Exit Sub
.RemoveItem row_LB
.ListIndex = -1
End With
With Sheets("Stock")
.Range("A1:N1").Offset(row_LB).Delete xlShiftUp
End With
With Sheets("Salidas")
.Range("A1:N1").Offset(row_LB).Delete xlShiftUp
End With
'Suma los valores del listbox después de eliminar filas en listbox
Dim canTotal As Currency
Dim cosTotal As Currency
For varRow = 1 To (ListBox1.ListCount - 1)
canTotal = canTotal + CCur(ListBox1.List(varRow, 2))
cosTotal = cosTotal + CCur(ListBox1.List(varRow, 4))
Next
TextBox18 = Format(canTotal, "#,##0.00")
TextBox19 = Format(cosTotal, "#,##0.00")
With Sheets("ValeCompras")
.Range("A12:D12").Offset(row_LB).Delete xlShiftUp
i = 13
Do While .Cells(i, "A").Value <> ""
i = i + 1
Loop
.Rows(i).Insert
End With
End Sub