excel - VBA 中的目标搜索
问题描述
我有一系列迭代需要将目标值执行为“0”。但是经过一系列的迭代,goalseek 似乎并没有正确执行它的任务。
我附上了非零的目标目标值。
Sub BP_design()
i = 1
Sheets("Reactions").Activate
With Sheets("Reactions")
Do While .Cells(i + 1, 3) <> ""
ND = .Cells(i + 1, 11)
LC = .Cells(i + 1, 12)
FX = Abs(.Cells(i + 1, 13))
Fy = .Cells(i + 1, 14)
FZ = Abs(.Cells(i + 1, 15))
Mx = Abs(.Cells(i + 1, 16))
My = Abs(.Cells(i + 1, 17))
Mz = Abs(.Cells(i + 1, 18))
''''''''''''''''''''''''''''''''
Sheets("Base_Plate").Cells(62, 2) = ND
Sheets("Base_Plate").Cells(59, 8) = LC
Sheets("Base_Plate").Cells(62, 5) = FX
Sheets("Base_Plate").Cells(62, 8) = Fy
Sheets("Base_Plate").Cells(62, 11) = FZ
Sheets("Base_Plate").Cells(62, 14) = Mx
Sheets("Base_Plate").Cells(62, 17) = My
Sheets("Base_Plate").Cells(62, 20) = Mz
''''''''''''''''''''''''''''''''
.Cells(i + 1, 20) = Sheets("Base_Plate").Cells(95, 25) 'F
.Cells(i + 1, 21) = Sheets("Base_Plate").Cells(96, 25) 'e
.Cells(i + 1, 22) = Sheets("Base_Plate").Cells(97, 25) 'K1
.Cells(i + 1, 23) = Sheets("Base_Plate").Cells(98, 25) 'K2
.Cells(i + 1, 24) = Sheets("Base_Plate").Cells(99, 25) 'K3
''''''''''''''''''''''''''''''''
Sheets("Base_Plate").Cells(104, 23).GoalSeek Goal:=0, ChangingCell:=Sheets("Base_Plate").Cells(105, 5)
.Cells(i + 1, 26) = Sheets("Base_Plate").Cells(105, 5)
.Cells(i + 1, 25) = Sheets("Base_Plate").Cells(104, 23) '0
''''''''''''''''''''''''''''''''
.Cells(i + 1, 27) = Sheets("Base_Plate").Cells(111, 23)
.Cells(i + 1, 28) = Sheets("Base_Plate").Cells(114, 23)
.Cells(i + 1, 30) = Sheets("Base_Plate").Cells(116, 23)
''''''''''''''''''''''''''''''''
.Cells(i + 1, 32) = Sheets("Base_Plate").Cells(118, 23)
.Cells(i + 1, 33) = Sheets("Base_Plate").Cells(120, 23)
.Cells(i + 1, 34) = Sheets("Base_Plate").Cells(123, 23)
.Cells(i + 1, 35) = Sheets("Base_Plate").Cells(130, 15)
''''''''''''''''''''''''''''''''
i = i + 1
Loop
End With
End Sub
解决方案
目标搜索的准确性取决于执行了多少计算才能到达目标。尝试在选项 > 公式中提高最大值
或在 VBA 中使用Application.MaxIterations
属性:https ://docs.microsoft.com/en-us/office/vba/api/excel.application.maxiterations
推荐阅读
- sql - 无法使用 WHERE 过滤(无法访问 ARRAY 类型的值的字段小时
#standardSQL SELECT DISTINCT geoNetwork.country FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*` WHERE _TABLE_SUFFIX
- javascript - 如何正确添加 Google ReCaptcha
- java - Java比较对象的效率
- apache - Apache Directory Studio 未打开
- ios - 如何使用情节提要为导航栏中的视图设置宽度和高度约束?
- google-sheets - 谷歌表格,重复的文字
- html - 如何在 html 和 css 中制作线条
- kotlin - Kotlin kapt 参数一个键的多个值
- php - 从php中的api单独打印多维数组
- java - 无法将edittext中的值转换为字符串