Hello
I have made the following VBA code, and it works.. But I would like to make it start over again if they write a number, that does not exist. And again. So it asks about rewritting the number, if it does not exist. I have marked it with red .
Sub Fjernelse()
Dim iRemove As Integer
iRemove = MsgBox("Do you want to delete a car?", vbYesNo)
Do While iRemove = vbYes
iRemove = InputBox("Which car do you want to remove? Write the number of the car:")
If iRemove = Range("A2").Value Then
Range("A2:C2").Select
Selection.ClearContents
Range("A3:C6").Select
Selection.Copy
Range("A2").Select
ActiveSheet.Paste
ElseIf iRemove = Range("A3").Value Then
Range("A3:C3").Select
Selection.ClearContents
Range("A4:C6").Select
Selection.Copy
Range("A3").Select
ActiveSheet.Paste
ElseIf iRemove = Range("A4").Value Then
Range("A4:C4").Select
Selection.ClearContents
Range("A5:C6").Select
Selection.Copy
Range("A4").Select
ActiveSheet.Paste
ElseIf iRemove = Range("A5").Value Then
Range("A5:C5").Select
Selection.ClearContents
Range("A6:C6").Select
Selection.Copy
Range("A5").Select
ActiveSheet.Paste
ElseIf iRemove = Range("A6").Value Then
Range("A6:C6").Select
Selaction.ClearContents
Else: MsgBox ("The number of the car do not exist. Try again")
'I want to ask the question again, where it does the same again.
End If
MsgBox ("Car number " & iRemove & " is now removed.")
Loop
End Sub
Thanks
I have made the following VBA code, and it works.. But I would like to make it start over again if they write a number, that does not exist. And again. So it asks about rewritting the number, if it does not exist. I have marked it with red .
Sub Fjernelse()
Dim iRemove As Integer
iRemove = MsgBox("Do you want to delete a car?", vbYesNo)
Do While iRemove = vbYes
iRemove = InputBox("Which car do you want to remove? Write the number of the car:")
If iRemove = Range("A2").Value Then
Range("A2:C2").Select
Selection.ClearContents
Range("A3:C6").Select
Selection.Copy
Range("A2").Select
ActiveSheet.Paste
ElseIf iRemove = Range("A3").Value Then
Range("A3:C3").Select
Selection.ClearContents
Range("A4:C6").Select
Selection.Copy
Range("A3").Select
ActiveSheet.Paste
ElseIf iRemove = Range("A4").Value Then
Range("A4:C4").Select
Selection.ClearContents
Range("A5:C6").Select
Selection.Copy
Range("A4").Select
ActiveSheet.Paste
ElseIf iRemove = Range("A5").Value Then
Range("A5:C5").Select
Selection.ClearContents
Range("A6:C6").Select
Selection.Copy
Range("A5").Select
ActiveSheet.Paste
ElseIf iRemove = Range("A6").Value Then
Range("A6:C6").Select
Selaction.ClearContents
Else: MsgBox ("The number of the car do not exist. Try again")
'I want to ask the question again, where it does the same again.
End If
MsgBox ("Car number " & iRemove & " is now removed.")
Loop
End Sub
Thanks