excel - 在公式中插入变量
问题描述
我有一个单元格,其中包含以下内容:
=$H$10+1&","&B5+I10&","&(2*$D$2+$E$2)/2
此公式的结果采用以下格式:
14649,28.25,5.5
我想使用公式 VBA 代码。我希望1
in 中的数字$H$10+**1**&"
是 for 循环的 i 并且I10
in"&B5+I10&"
也随着循环而变化。
For i=1 to lastrow
.Range("X" & 13+i & "").Formula = "=$H$10+" & i & "" & "," & "B5+I" & i + 10 & "" & "," & "(2*$D$2+$E$2)/2"
Next i
解决方案
这里可以使用的代码:
Sub mySub()
'=$H$10+1&","&B5+I10&","&(2*$D$2+$E$2)/2
Dim myRange As Range
Set myRange = Range("H:H").SpecialCells(xlCellTypeLastCell)
Dim myStr As String
'A=10 is for assigning first row in H as your data, hope no data upward from row 9 to row 1
For Baris = 10 To myRange.Row
On Error Resume Next
myStr = "=$H$10+" & Baris - 9 & "&"",""&B5+I" & Baris & "&"",""&(2*$D$2+$E$2)/2"
Range("K" & Baris).Formula = myStr
Next
End Sub
推荐阅读
- java - DocuSign Java API 信封Api.getDocument 返回 NULL 异常
- python - 按索引的嵌套列表操作
- angular - UTC 时区中的 Material Datepicker 小部件
- sql - 将表名作为参数传递给多个 SELECT
- javascript - 如何使用 javascript 包含过滤掉不包含特定文本的文本
- google-kubernetes-engine - GKE 中的 Kubenet 风格网络
- twitter - 将(公开)推文嵌入 Google Data Studio
- c# - 如何在实现 C# 非泛型接口泛型属性时跳过传递类型?
- xml - Mule 中的 DataWeave 转换
- c# - 有什么办法可以让我在 C# 控制台应用程序中同时播放两种声音?