for 循环遇到问题。我实际上有一组 5 个单元格,然后需要经历一个循环,这将影响不同页面上的计算。这些计算将为我提供一系列数据点,然后我想将其复制到新页面,然后重复该过程。
输出应该是计算选项卡中的一系列单元格,我想将其粘贴到 Output_tab 中。
示例代码如下。
Sub Loop_seek
Dim i as Integer Dim Output_tab as Worksheet
For i = 1 to 6
Range ("Selection_C").Value = Cells(i + 10, B).Value
'this is value that changes selections on the next page for calculations
Changeamount.Value = Cells (i +10, C)
'is the value that will be changed to goal seek to value
Range("TestAmount").GoalSeek:=0, ChangingCell:= Changeamount
'productvalue is a named range of cells on the calculation tap I want to copy to a new tab and print
Range("productvalue").copy Destination=Output_tab (I+2, D)
'pasting in defined tab starting in column d with the applicable row
Next i
End Sub
最佳猜测
Option Explicit
Sub Loop_seek()
Dim wsInput As Worksheet, wsOutput As Worksheet, i As Long
With ThisWorkbook
Set wsInput = ActiveSheet ' or better .Sheets("Input_tab")
Set wsOutput = .Sheets("Output_tab")
End With
With wsInput
For i = 1 To 6
Range("Selection_C") = .Cells(i + 10, "B")
'this is value that changes selections on the next page for calculations
Range("ChangeAmount") = .Cells(i + 10, "C")
'is the value that will be changed to goal seek to value
Range("TestAmount").GoalSeek Goal:=0, ChangingCell:=Range("ChangeAmount")
'productvalue is a named range of cells on the calculation tap
'I want to copy to a new tab and print
Range("productvalue").Copy wsOutput.Cells(i + 2, "D")
'pasting in defined tab starting in column d with the applicable row
Next i
End With
End Sub