Hello Everyone
I have a spreadsheet (sheet1) with several general article data, and a second spreadsheet (sheet2) that specifies one of them, with a different record order.
I would like to use a command in the userform, so that when I wanted to delete a certain record, on sheet 1, it would be deleted on the line of the corresponding sheet on sheet 2.
The difference between the record on sheet1 and sheet2 is only the entry order number, the rest is the same.
My thanks for anyone who can help me.
What I use is below:
I have a spreadsheet (sheet1) with several general article data, and a second spreadsheet (sheet2) that specifies one of them, with a different record order.
I would like to use a command in the userform, so that when I wanted to delete a certain record, on sheet 1, it would be deleted on the line of the corresponding sheet on sheet 2.
The difference between the record on sheet1 and sheet2 is only the entry order number, the rest is the same.
My thanks for anyone who can help me.
What I use is below:
VBA Code:
Private Sub CmdB1_Click() 'DELETE
Dim i, ip As Long
Dim Ws As Worksheet
Dim r As Long
Dim NextRow, RowUlt As Long
Dim linha As Integer
Application.ScreenUpdating = False
On Error Resume Next
'delete data,without reference to products
Set Ws = Sheets("imputdata")
NextRow = Ws.Range("b" & Rows.Count).End(xlUp).Row + 5
If ListBox1.Value = "" Then
MsgBox ("Please fill up, the Months or Value commands, and select them")
End If
With ListBox1
If MsgBox("Are you sure you want to delete this row?", vbYesNo + vbQuestion, "Delete row") = vbNo Then
Exit Sub
Else
For i = 1 To Sheet1.Range("b10000").End(xlUp).Row
If Sheet1.Cells(i, "B") = Val(Me.ListBox1.Column(0)) Then
Sheet1.Range("B" & i).EntireRow.Delete
ListBox2.Clear
End If
Next i
For ip = 1 To Sheet2.Range("b10000").End(xlUp).Row
If Sheet2.Cells(ip, "B") = Val(Me.ListBox1.Column(0)) Then
Sheet2.Range("B" & ip).EntireRow.Delete
ListBox2.Clear
End If
Next ip
end with
end sub