我正在尝试在Excel VBA中创建一个宏,该宏将目标搜索多行。 B列是我的“设置值”,C列是更改的值,D列是我的“目标值”。下面是我当前的代码。我是VBA的新手,非常感谢您的帮助和耐心等待!
Sub dynamicgoalseek()
Dim i As Integer ' i used for loop
Dim sht As Worksheet
Dim LastRow As Long
Set sht = ThisWorkbook.Worksheets(Sheet1.Name)
' used to count rows in column B
LastRow = sht.Cells(sht.rows.Count, "B").End(xlUp).Row
' start of loop
For i = 1 To LastRow
'set B to value in D by changing C
Range("b", i).GoalSeek Goal:=Range("d", i), ChangingCell:=Range("c", i)
' end loop
Next i
End Sub
编辑:我在运行时遇到应用程序定义或对象定义的错误。