我正在制作一个原型工作表,遵循9步问题解决程序,但我最终得到了这个非常草率的代码。我想迭代其中一些,而不是为每个变体创建一个新的代码行。或多或少我需要优化这段代码,这样我才能学会如何在将来做这类事情。我应该能够用我认为的集合做到这一点,但我之前从未使用过集合,我可以使用一些帮助。这不是一个非常直接的循环过程,我无法想出任何好的方法来设置它。 Here is a picture of the sheet that the values will go into.
这是我的代码
Sub nine_Step()
Dim step1, step2, step3, step4a, step4b, step4c, step4d, step4e, step5a, step5b, step5c, step5d, step5e, step6a, step6b, step6c, step6d, step6e, step7, step8, step9 As Variant
step1 = InputBox("Step 1: Define the Problem.")
Cells(2, 3).Value = step1
step2 = InputBox("Step 2: What is the Measured Actual Value?")
Cells(4, 3).Value = step2
step3 = InputBox("Step 3: What is the Target Value Desired?")
Cells(6, 3).Value = step3
If step3 <> "" Then
Cells(7, 3).Value = step3 - step2
Else:
End If
step4a = InputBox("Step 4: Why is " & step1 & " happening?")
Cells(9, 3).Value = step4a
step4b = InputBox("Step 4: Why is " & step4a & " happening?")
Cells(10, 3).Value = step4b
step4c = InputBox("Step 4: Why is " & step4b & " happening?")
Cells(11, 3).Value = step4c
step4d = InputBox("Step 4: Why is " & step4c & " happening?")
Cells(12, 3).Value = step4d
step4e = InputBox("Step 4: Why is " & step4d & " happening?")
Cells(13, 3).Value = step4e
step5a = InputBox("Step 5: Describe your First Possible Solution")
Cells(15, 3).Value = step5a
step5b = InputBox("Step 5: Describe your Second Possible Solution")
Cells(16, 3).Value = step5b
step5c = InputBox("Step 5: Describe your Third Possible Solution")
Cells(17, 3).Value = step5c
step5d = InputBox("Step 5: Describe your Fourth Possible Solution")
Cells(18, 3).Value = step5d
step5e = InputBox("Step 5: Describe your Fifth Possible Solution")
Cells(19, 3).Value = step5e
step6a = InputBox("Step 6: Experiment Measurement Results Solution 1")
Cells(21, 3).Value = step6a
step6b = InputBox("Step 6: Experiment Measurement Results Solution 2")
Cells(22, 3).Value = step6b
step6c = InputBox("Step 6: Experiment Measurement Results Solution 3")
Cells(23, 3).Value = step6c
step6d = InputBox("Step 6: Experiment Measurement Results Solution 4")
Cells(24, 3).Value = step6d
step6e = InputBox("Step 6: Experiment Measurement Results Solution 5")
Cells(25, 3).Value = step6e
step7 = InputBox("Step 7: When did you impliment a solution? Enter a date in
XX/XX/XXXX format")
If step7 = "" Then
MsgBox ("Find out when you implimented a solution and enter it when you get a chance.")
Else:
Cells(28, 3).Value = step7
End If
step8 = InputBox("Step 8: Now that the solution is implemented perminently, what is the current measurement?")
Cells(31, 3).Value = step8
If step8 <> "" Then
Cells(32, 3).Value = Cells(6, 3).Value - step8
Else:
End If
step9 = InputBox("Step 9: Any other Ideas that have sprung up since you have started this nine step related to this area?")
Cells(34, 3).Value = step9
MsgBox ("You have successfully completed this 9 Step. Congrats!")
End Sub