I have a worksheet "Database" that has data that I want to search and delete[cut paste to another worksheet named "Cleared"]. So I have an input dialog that I input the FS Numbers as a string separated by comma, I then split the text using Split()
function to get the number. I have used for loop
to get single row with a column matching the FS Number.
I have my VBA code as this
Sub DeleteRecord()
Dim iRow As Long
Dim iSerial As String
Dim DisplayText As String
Dim Result() As String
Dim i As Long
iSerial = Application.InputBox("Please enter FS Number to delete", "Delete", , , , , , 2)
'MsgBox (iSerial)
Result = Split(iSerial, ",")
'MsgBox Result(0)
'MsgBox Result(2)
On Error Resume Next
For i = LBound(Result()) To UBound(Result())
iRow = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Match(Result(i), Sheets("Database").Range("B:B"), 0), 0)
'MsgBox Result(i)
Sheets("Database").Rows(iRow).Cut
Worksheets("Cleared").Activate
b = Worksheets("Cleared").Cells(Rows.Count, 2).End(xlUp).Row
Worksheets("Cleared").Cells(b + 1, 1).Select
ActiveSheet.Paste
Cells(b + 1, 10).Value = [Text(now(),"DD-MM-YYYY HH:MM:SS")]
Worksheets("Form").Activate
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Form").Cells(1, 1).Select
'MsgBox Result(i)
Next i
'For i = LBound(Result()) To UBound(Result())
'DisplayText = DisplayText & Result(i) & vbNewLine
'Next i
'MsgBox DisplayText
On Error GoTo 0
If iRow = 0 Then
MsgBox "No record found.", vbOKOnly + vbCritical, "No Record"
Worksheets("Form").Activate
ThisWorkbook.Worksheets("Form").Cells(1, 1).Select
Exit Sub
End If
End Sub
When i run the code, the "Cleared" worksheet doesn't have any value. Where am I doing wrong?