Excel生成迭代单元格引用

时间:2015-07-19 21:26:12

标签: excel excel-formula

有没有办法生成Excel Cell引用?我一直在手动迭代以下内容:

=($B$12-C12)*$B$3*C3
=($C$12-D12)*$C$3*D3
=($D$12-E12)*$D$3*E3
=($E$12-F12)*$E$3*F3
=($F$12-G12)*F$3*G3
=($G$12-H12)*$G$3*H3
=($H$12-I12)*$H$3*I3
=($I$12-J12)*$I$3*J3
=($J$12-K12)*$J$3*K3
=($K$12-L12)*$K$3*L3
=($L$12-M12)*$L$3*M3
=($M$12-N12)*$M$3*N3
=($N$12-O12)*$N$3*O3
=($O$12-P12)*$O$3*P3
=($P$12-Q12)*$P$3*Q3
=($Q$12-R12)*$Q$3*R3
=($R$12-S12)*$R$3*S3
=($S$12-T12)*$S$3*T3
=($T$12-U12)*$T$3*U3
=($U$12-V12)*$U$3*V3
=($V$12-W12)*$V$3*W3
=($W$12-X12)*$W$3*X3
=($X$12-Y12)*$X$3*Y3
=($Y$12-Z12)*$Y$3*Z3
=($Z$12-AA12)*$Z$3*AA3
..
..
..
..
..
..

2 个答案:

答案 0 :(得分:0)

使用Row获取行号,然后使用Offset从参考点偏移相对于行号的列数。例如:

=(OFFSET(A1,0,ROW(B1))-OFFSET(A1,0,ROW(B1)+1))*OFFSET(A1,0,ROW(B1))*OFFSET(A1,0,ROW(B1)+1)

假设您的数据从B1和C1开始

答案 1 :(得分:0)

我可以想象没有比打字更无聊的事情。尝试下面,我假设你想要代码打印到单元格?这比你想要的多了几个,让我知道这是不是问题。另外,只需将countto变量更改为所需的迭代次数即可。希望它有所帮助。

Sub poorguy()
Dim counter As Long
Dim countto As Long
Dim col1 As String
Dim col2 As String
Dim col3 As String
Dim col4 As String
Dim rngwrite As Range

counter = 0
countto = 100

For i = 0 To countto
    col1 = cells(12, 2).Offset(0, counter).Address
    col2 = cells(12, 3).Offset(0, counter).Address
    col3 = cells(3, 2).Offset(0, counter).Address
    col4 = cells(3, 3).Offset(0, counter).Address
    Set rngwrite = cells(1, 1).Offset(counter, 0)
    rngwrite.Value = "=(" & col1 & "-" & col2 & ")*" & col3 & "*" & col4
    counter = counter + 1
Next
Set rngwrite = Nothing
End Sub