如何引用已在Sheet公式VBA中find的列
我有以下的VBA问题。 我有一个代码afind一列,然后在另一列插入工作表公式。 该公式包含对以前find的列的引用。
Dim intBB As Integer Dim rngBB As Range Dim controlBB As Integer intBB = 1 Do While Worksheets("Sheet2").Cells(2, intBB) <> "" If Worksheets("Sheet2").Cells(2, intBB).Value = "BbCode" Then With Worksheets("Sheet2") Set rngBB = .Range(.Cells(2, intBB), .Cells(2, intBB)) controlBB = intBB End With Exit Do End If intBB = intBB + 1 Loop Worksheets("Sheet2").Range("W3:W2500").Formula = "= _ IF (controlBB="""","""",BDP(controlBB&"" Equity"",""ID_ISIN""))"
但是,这是行不通的。 我怎样才能正确引用find的列?
既然你有一个列号,而不是字母,我会build议使用R1C1格式:
Worksheets("Sheet2").Range("W3:W2500").FormulaR1C1 = "= _ IF (RC" & controlBB & "="""","""",BDP(RC" & controlBB & "&"" Equity"",""ID_ISIN""))"
这是我将如何做到这一点
For i = 3 To 2500 Worksheets("Sheet2").Range("a" & i).Formula = "=IF(" & Cells(i, controlBB).Address & "="""","""",BDP(" & Cells(i, controlBB).Address & " & "" Equity"",""ID_ISIN""))" Next i