I am trying to automate repetitive tasks by using .inputboxes in Excel.
Note: CopyAmt
is an integer returned from another InputBox
, userInputRange
is type 8 box, and RowCnt
is the Row.Count
of userInputRange
.
For i = 1 To CopyAmt
userInputRange.Copy
ActiveCell.Offset(RowCnt, 0).Activate
ActiveCell.PasteSpecial
ActiveSheet.Range(ActiveCell.Offset(, 24), ActiveCell.Offset(RowCnt - 1, 24)).Value = Application.InputBox(Prompt:="Internal Value", Type:=2)
Next i
If a user was to click Cancel, I would want to exit the sub only after deleting the selection that was just pasted on line 4 of the above code. This is what I was trying.
For i = 1 To CopyAmt
userInputRange.Copy
ActiveCell.Offset(RowCnt, 0).Activate
ActiveCell.PasteSpecial
ActiveSheet.Range(ActiveCell.Offset(, 24), ActiveCell.Offset(RowCnt - 1, 24)).Value = Application.InputBox(Prompt:="Internal Value", Type:=2)
If ActiveSheet.Range(ActiveCell.Offset(, 24), ActiveCell.Offset(RowCnt - 1, 24)).Value = False Then
Selection.Delete
Exit Sub
End If
Next i
This results in a mistype and I would love some clarification on the things I am doing wrong, or just not efficiently.
Thank you for your time.