gpt4 book ai didi

VBA - 缩短重复的公式分配

转载 作者:行者123 更新时间:2023-12-03 02:30:11 25 4
gpt4 key购买 nike

我想缩短我非常重复的代码,其中有很多这样的行:

.Range("AB81") = "=VLOOKUP(I65,'[" & R1 & "]" & "Investments" & "'! $B$58:$F$81," & 5 & ",0)"
.Range("AD81") = "=VLOOKUP(K65,'[" & R1 & "]" & "Investments" & "'! $B$58:$F$81," & 5 & ",0)"
.Range("AF81") = "=VLOOKUP(M65,'[" & R1 & "]" & "Investments" & "'! $B$58:$F$81," & 5 & ",0)"
.Range("AH81") = "=VLOOKUP(O65,'[" & R1 & "]" & "Investments" & "'! $B$58:$F$81," & 5 & ",0)"
.Range("AJ81") = "=VLOOKUP(Q65,'[" & R1 & "]" & "Investments" & "'! $B$58:$F$81," & 5 & ",0)"
.Range("AL81") = "=VLOOKUP(S65,'[" & R1 & "]" & "Investments" & "'! $B$58:$F$81," & 5 & ",0)"

.Range(..81) 范围每次移动 2 列,VLOOKUP 公式中的第一个范围也是如此。

最佳答案

一次设置所有公式时,相对引用会自动调整:

.Range("AB81,AD81,AF81,AH81,AJ81,AL81").Formula = _
"=VLOOKUP(I65,'[" & R1 & "]" & "Investments" & "'!$B$58:$F$81," & 5 & ",0)"

关于VBA - 缩短重复的公式分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43975132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com