Repeat the question and if again in funktion

Annemus

New Member
Joined
May 22, 2011
Messages
15
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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top