VBA应用EXCEL公式

tech2022-08-22  119

' 七个使用公式的例子 ' '1、行标是变量的例子 '2、列标用一维数组输入字符串做列标,行标是变量 '3、用RC做相对引用 '4、RC和变量混合 '5、整列使用RC引用,避免使用循环 '6、整个区域RC引用——相对引用/循环 '7、整个区域RC应用——相对引用/不用循环 Sub 数例() [a1] = "1a": [a2] = "d2": [a3] = "cd": [a4] = "fa" End Sub Sub ts1() For i = 1 To 4 Cells(i, 2).Formula = "=left(A" & i & ",1)" Next i End Sub Sub ts2() arr = Array("A", "B", "C", "D", "F", "E") For i = 1 To 4 Cells(i, 3).Formula = "=left(" & arr(0) & i & ",1)" Next i End Sub Sub ts3() For i = 1 To 4 Cells(i, 4).FormulaR1C1 = "=left(RC[-3],1)" Next End Sub Sub ts4() j = -4 For i = 1 To 4 Cells(i, 5).FormulaR1C1 = "=left(RC[" & j & "],1)" Next End Sub Sub ts5() j = -4 Cells(1, 6).Resize(4).FormulaR1C1 = "=left(RC[" & j & "],1)" End Sub Sub ts6() For j = 1 To 4 Cells(1, 6).Resize(4, j).FormulaR1C1 = "=left(RC[" & -5 & "],2)" Next End Sub Sub ts7() Cells(6, 6).Resize(4, 4).FormulaR1C1 = "=left(R[-5]C[" & -5 & "],2)" End Sub
最新回复(0)