在公式中使用最后一行计数
Use the last row count in a formula
下面的代码允许我将公式从第 2 行重复到所有行,直到最后一个活动行。
Dim LastRow As Long
With Sheets("C PUR TYPE")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("M2:M" & LastRow).formula = "=IFERROR(RIGHT(SUBSTITUTE(Lookup_concat(A2,$A:$A1932,$L:$L1932),"" 0,"",""""),LEN(SUBSTITUTE(Lookup_concat(A2,$A:$A1932,$L:$L1932),"" 0,"",""""))-2),"" - "")"
End With
在此实例中,有 1'932 个活动行。
有什么方法可以将公式中的单元格引用 :$A1932 和 $L1932 替换为使用最后一行计数,因为每次运行报表时行计数都会不同。
谢谢
使用 &
将允许您将变量连接到字符串中:
Dim LastRow As Long
With Sheets("C PUR TYPE")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("M2:M" & LastRow).formula = "=IFERROR(RIGHT(SUBSTITUTE(Lookup_concat(A2,$A:$A" & LastRow & ",$L:$L" & LastRow & "),"" 0,"",""""),LEN(SUBSTITUTE(Lookup_concat(A2,$A:$A" & LastRow & ",$L:$L" & LastRow & "),"" 0,"",""""))-2),"" - "")"
End With
在我看来,您可以使用与计算方式类似的变量 lastRow
。
示例(假设您在 A 列中没有任何空白):
dim LookupLastrow as long
LookupLastrow=range("A1").end(xldown).row
然后将公式中的 1932 引用替换为“& lookuplastrow &”:
.Range("M2:M" & LastRow).formula = "=IFERROR(RIGHT(SUBSTITUTE(Lookup_concat(A2,$A:$A" & lookuplastrow & ",$L:$L" & lookuplastrow & "),"" 0,"",""""),LEN(SUBSTITUTE(Lookup_concat(A2,$A:$A" & lookuplastrow & ",$L:$L" & lookuplastrow & "),"" 0,"",""""))-2),"" - "")"
下面的代码允许我将公式从第 2 行重复到所有行,直到最后一个活动行。
Dim LastRow As Long
With Sheets("C PUR TYPE")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("M2:M" & LastRow).formula = "=IFERROR(RIGHT(SUBSTITUTE(Lookup_concat(A2,$A:$A1932,$L:$L1932),"" 0,"",""""),LEN(SUBSTITUTE(Lookup_concat(A2,$A:$A1932,$L:$L1932),"" 0,"",""""))-2),"" - "")"
End With
在此实例中,有 1'932 个活动行。
有什么方法可以将公式中的单元格引用 :$A1932 和 $L1932 替换为使用最后一行计数,因为每次运行报表时行计数都会不同。
谢谢
使用 &
将允许您将变量连接到字符串中:
Dim LastRow As Long
With Sheets("C PUR TYPE")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("M2:M" & LastRow).formula = "=IFERROR(RIGHT(SUBSTITUTE(Lookup_concat(A2,$A:$A" & LastRow & ",$L:$L" & LastRow & "),"" 0,"",""""),LEN(SUBSTITUTE(Lookup_concat(A2,$A:$A" & LastRow & ",$L:$L" & LastRow & "),"" 0,"",""""))-2),"" - "")"
End With
在我看来,您可以使用与计算方式类似的变量 lastRow
。
示例(假设您在 A 列中没有任何空白):
dim LookupLastrow as long
LookupLastrow=range("A1").end(xldown).row
然后将公式中的 1932 引用替换为“& lookuplastrow &”:
.Range("M2:M" & LastRow).formula = "=IFERROR(RIGHT(SUBSTITUTE(Lookup_concat(A2,$A:$A" & lookuplastrow & ",$L:$L" & lookuplastrow & "),"" 0,"",""""),LEN(SUBSTITUTE(Lookup_concat(A2,$A:$A" & lookuplastrow & ",$L:$L" & lookuplastrow & "),"" 0,"",""""))-2),"" - "")"