嗨我有一段代码,我正在尝试编写一个循环,但我正在努力如何去做。Excel循环VBA增量行
这部分代码运行良好。但我实际上有4个单元格,即C26,C91,C156和C221。 (请参阅代码中的容器1注释)
我设法让它循环,但是接下来我的引用(例如B33,C33,D33等)只是写在顶端。无论如何写一个循环,可以递增所需的65行所有的后续代码?
我真的很想学习如何正确执行此操作,而不是复制并粘贴4次并手动更新引用!
Private Sub RunStabSetup()
' Confirmation of Entry to Form
If MsgBox("Have you double checked your data is correct and ALL test points have been selected before entering on the spreadsheet?", vbYesNo) = vbNo Then Exit Sub
Application.ScreenUpdating = False
Application.Worksheets("Req Sheet").Range("C83") = " "
If Container1CB.Value > "" Then
'Container 1
Application.Worksheets("StabDataCapture").Range("C26") = Container1CB
'60° CheckBox logic statements
If W1T60.Value = True Then Application.Worksheets("StabDataCapture").Range("B33") = "1"
If W1T60.Value = False Then Application.Worksheets("StabDataCapture").Range("B33") = ""
If W2T60.Value = True Then Application.Worksheets("StabDataCapture").Range("C33") = "2"
If W2T60.Value = False Then Application.Worksheets("StabDataCapture").Range("C33") = ""
If W3T60.Value = True Then Application.Worksheets("StabDataCapture").Range("D33") = "3"
If W3T60.Value = False Then Application.Worksheets("StabDataCapture").Range("D33") = ""
If W4T60.Value = True Then Application.Worksheets("StabDataCapture").Range("E33") = "4"
If W4T60.Value = False Then Application.Worksheets("StabDataCapture").Range("E33") = ""
If W5T60.Value = True Then Application.Worksheets("StabDataCapture").Range("F33") = "5"
If W5T60.Value = False Then Application.Worksheets("StabDataCapture").Range("F33") = ""
If W6T60.Value = True Then Application.Worksheets("StabDataCapture").Range("G33") = "6"
If W6T60.Value = False Then Application.Worksheets("StabDataCapture").Range("G33") = ""
If W7T60.Value = True Then Application.Worksheets("StabDataCapture").Range("H33") = "7"
If W7T60.Value = False Then Application.Worksheets("StabDataCapture").Range("H33") = ""
If W8T60.Value = True Then Application.Worksheets("StabDataCapture").Range("I33") = "8"
If W8T60.Value = False Then Application.Worksheets("StabDataCapture").Range("I33") = ""
End If
End Sub
感谢您帮助大家!
'W1T60'值是否也会增加?我假设你想要B33 = 1,C33 = 2,如果我们想要Z33,你想要Z33 = 25? – BruceWayne