I have a user form setup to add rows to my report based on a number input into "textboxDIMS." I start with 2 row so that I can copy and paste the bottom one that does not have the darker border on top (merely for cosmetics) Once and a while I will only need one row of data so I have a case setup to delete the bottom row. When I try to run this scenario, excel locks up. Any ideas why? Line 1 in the case below (Highlighted in RED)is what is supposed to do the trick.
Thanks in advance for looking at this!
Private Sub CommandButton1_Click()
'Adds variables from user form to sheet 1
With ActiveWorkbook.Sheets("sheet1")
Sheets("sheet1").Range("C2:F3").ClearContents
Sheets("sheet1").Range("C2").Value = TextBoxPARTS.Value
Sheets("sheet1").Range("D2").Value = TextBoxDIMS.Value
Sheets("sheet1").Range("E2").Value = TextBoxTRIALS.Value
Sheets("sheet1").Range("F2").Value = TextBoxTOL.Value
If OptionButton1 = True Then
Sheets("sheet1").Range("G2").Value = "6.00"
Else
Sheets("sheet1").Range("G2").Value = "5.15"
End If
End With
' Add_Rows_Devaiation Macro
' Macro recorded 9/9/2002 by Gary
' Macro edited 10/24/2007 by Mike
' Macro edited 01/06/2009 by Mike
Application.ScreenUpdating = False
Dim Check, Counter, Features As Range, Message, Title, Default, FeaturesValue
Dim MLRValue
TextBoxPARTS = Val(TextBoxPARTS.Text)
TextBoxDIMS = Val(TextBoxDIMS.Text)
TextBoxTRIALS = Val(TextBoxTRIALS.Text)
FeaturesValue = TextBoxDIMS
Select Case FeaturesValue
Case 0: GoTo line3
Case 1: GoTo line1
Case 2: GoTo Line4
Case Is > 2: GoTo line2
End Select
line1:
Rows(8).Delete
Range("J7").Select
Unload Me
line2:
FeaturesValue = FeaturesValue - 2
Check = True: Counter = FeaturesValue ' Add number of features
ActiveSheet.Rows(8).Select
Selection.Copy
Do ' Outer loop.
Do While Counter > 0 ' Inner loop.
Counter = Counter - 1 ' Increment Counter.
ActiveCell.Offset(1, 0).Activate
ActiveSheet.Paste
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("J7").Select
GoTo Line4
line3:
MsgBox "You can not have 0 features in this report. Please try again.", vbOKOnly
Unload Me
Line4:
Unload Me
End Sub