LR = Range("AB" & Rows.Count).End(xlUp).Row
Range("AB7:AB" & LR).FormulaR1C1 = "=IF(RC[-9]=""Debit"",""Credit"",""Debit"")"
Dim num As Long
LR = Range("AC" & Rows.Count).End(xlUp).Row
Range("AC7:AC" & LR).FormulaR1C1 = "=abs(RC[-9])"这是我代码的底部。我正试图获得最后3行代码的结果(只是值),这些代码将粘贴到单元格T7中,直到数据结束。
发布于 2021-12-07 02:49:57
我没有答案,但我有解决办法!
当您有这样的Rose和列时,您可以高亮显示它们,包括标题行,然后从数据带中单击“插入表”。(或按下控制T)
除了允许您一次格式化整个表之外,调用他公式还可以按名称引用其他列,并且一个公式的列存储为该列的一个公式,而不管有多少行!有了这一点,您甚至可能根本不需要做任何编码来完成这一点,这取决于您的需求。..。或者,如果您确实需要更多的VBA,这个答案可能是无用的。尽管无视吧。
在VBA中,由于某种原因,表被称为ListObjects而不是“table”。请参阅https://learn.microsoft.com/en-us/office/vba/api/excel.listobject
发布于 2021-12-07 02:51:39
变量对With Statement
R1C1风格的
Sub UsingVariableR1C1()
Dim LR As Long: LR = Range("AC" & Rows.Count).End(xlUp).Row
' Declare a range variable.
Dim rg As Range
' Create a reference to the range.
Set rg = Range("AC7:AC" & LR).Offset(0, -9)
' Write formula.
rg.FormulaR1C1 = "=ABS(RC[9])"
' Convert to values.
rg.Value = rg.Value
End Sub
Sub UsingWithR1C1()
Dim LR As Long: LR = Range("AC" & Rows.Count).End(xlUp).Row
' Create a reference to the range using the With statement.
With Range("AC7:AC" & LR).Offset(0, -9)
' Write formula.
.FormulaR1C1 = "=ABS(RC[9])"
' Convert to values.
.Value = .Value
End With
End SubA1型
Sub UsingVariableA1()
Dim LR As Long: LR = Range("AC" & Rows.Count).End(xlUp).Row
' Declare a range variable.
Dim rg As Range
' Create a reference to the range.
Set rg = Range("T7:T" & LR)
' Write formula.
rg.Formula = "=ABS(AC7)"
' or:
'rg.Formula = "=ABS(" & rg.Cells(1).Offset(0, 9).Address(0,0) & ")"
' Convert to values.
rg.Value = rg.Value
End Sub
Sub UsingWithA1()
Dim LR As Long: LR = Range("AC" & Rows.Count).End(xlUp).Row
' Create a reference to the range using the With statement.
With Range("T7:T" & LR)
' Write formula.
.Formula = "=ABS(AC7)"
' or:
'.Formula = "=ABS(" & .Cells(1).Offset(0, 9).Address(0, 0) & ")"
' Convert to values.
.Value = .Value
End With
End Subhttps://stackoverflow.com/questions/70252705
复制相似问题