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 中,直到資料結束。
uj5u.com熱心網友回復:
我沒有答案,但我這樣做有一個解決方案!
當您有 Rose 和類似的列時,您可以突出顯示它們,包括標題行,然后從資料功能區中單擊“插入表格”。(或按控制T)
除了允許您一次格式化整個表格之外,稱他為公式可以通過名稱參考其他列,并且具有一個公式的列存盤為該列的一個公式,而不管有多少行!有了這個,根據您的需要,您甚至可能根本不需要進行任何編碼來完成這項作業。...或者,如果您確實需要 VBA 來處理更大的部分,則此答案可能沒用。隨意忽略。
在 VBA 中,出于某種原因,表被稱為 ListObjects 而不是“表”。請參閱https://docs.microsoft.com/en-us/office/vba/api/excel.listobject
uj5u.com熱心網友回復:
變數 vs 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 Sub
A1型
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 Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/375572.html
