pingwin77
03-17-2009, 01:01 PM
I have the follwing code assigned to a button. This allows me to enter how many parts I have on my report. When I click the "Cancel" button, I get an error. The Debug stops on the Highlighted line (RED). What am I doing wrong?
Private Sub CommandButtonADDparts_Click()
'
' AddParts Macro
' Macro recorded 5/7/2008 by AIS
Application.ScreenUpdating = False
Dim Check, Counter, Features As Range, Message, Title, Default, PartsValue
' Display message, title, and default value.
PartsValue = InputBox("Enter number of Parts", "Add Parts Columns", 0)
If PartsValue = 0 Then GoTo line2 Else GoTo line1
PartsValue = PartsValue - 1
line1:
Check = True: Counter = PartsValue ' Add number of parts
Range("J10").Select
Range("J10:K550").Select
Selection.Copy
Do ' Outer loop.
Do While Counter > 0 ' Inner loop.
Counter = Counter - 1 ' Increment Counter.
ActiveCell.Offset(0, 2).Activate
ActiveSheet.Paste
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = ActiveCell.Offset(0, -2) + 1
ActiveCell.Offset(0, -1).Activate
If Counter = 0 Then ' If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.
Application.CutCopyMode = False
Range("B12").Select
line2:
End Sub
Private Sub CommandButtonADDparts_Click()
'
' AddParts Macro
' Macro recorded 5/7/2008 by AIS
Application.ScreenUpdating = False
Dim Check, Counter, Features As Range, Message, Title, Default, PartsValue
' Display message, title, and default value.
PartsValue = InputBox("Enter number of Parts", "Add Parts Columns", 0)
If PartsValue = 0 Then GoTo line2 Else GoTo line1
PartsValue = PartsValue - 1
line1:
Check = True: Counter = PartsValue ' Add number of parts
Range("J10").Select
Range("J10:K550").Select
Selection.Copy
Do ' Outer loop.
Do While Counter > 0 ' Inner loop.
Counter = Counter - 1 ' Increment Counter.
ActiveCell.Offset(0, 2).Activate
ActiveSheet.Paste
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = ActiveCell.Offset(0, -2) + 1
ActiveCell.Offset(0, -1).Activate
If Counter = 0 Then ' If condition is True.
Check = False ' Set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.
Application.CutCopyMode = False
Range("B12").Select
line2:
End Sub