我有一个三步过程,最终应该给我布尔值 True/False 以及偶尔的 #N/A 或 #VALUE (我实际上希望将其保留为错误)。我正在使用具有多个命名工作表的工作簿,并通过 VLookup 从一个选项卡中提取单元格值,替换这些值中的字符串,然后将这些值放入要评估的公式中。这是我到目前为止所拥有的;我在代码中添加了注释,解释了我卡在哪里。
Public Sub DetermineRowsToExamine()
'Define what our Rows are for the calculations
Dim NumRecords As Long
NumRecords = Workbooks("POVA Daily Reporter.xlsm").Worksheets("Paste Daily Data").Range("B" & Rows.Count).End(xlUp).Row
Dim CellsForFormula As Range
Set CellsForFormula = Workbooks("POVA Daily Reporter.xlsm").Worksheets("Paste Daily Data").Range("g2", "G" & NumRecords)
'Now I Insert the VLookup
Dim WSLogic As Worksheet
Dim WSData As Worksheet
Set WSData = Workbooks("POVA Daily Reporter.xlsm").Worksheets("Paste Daily Data")
Set WSLogic = Workbooks("POVA Daily Reporter.xlsm").Worksheets("Logic Statements")
CellsForFormula.Value = Application.WorksheetFunction.VLookup(WSData.Range("B2"), WSLogic.Range("A:D"), 4, False)
'This works in principle, but the problem is the "B2" in the VLookup - I need the "B2" to change to "B3" related
'to each row, just as it would if I pasted the rows down the columns as an cell formula
'Now I want to take that value and perform a replacement:
CellsForFormula.Value = Application.WorksheetFunction.Substitute(Range("g2"), "ZZZ", "C2")
'Again, this works great, but I need it to replace "G2" or "G3" or whatever cell it's in.
'Finally, I then want to evaluate that cell as if it were a formula. When the above calculations are working,
'I end up with: AND(LEN(C2)=10,OR(LEFT(C2,2)="57",LEFT(C2,2)="13"))
'I want to evaluate this as a formula, basically making it =AND(LEN(C2)=10,OR(LEFT(C2,2)="57",LEFT(C2,2)="13"))
End Sub
我想我只是不理解的是如何让 VLookup 和 Substitute 函数中的 Cell 引用与我所在的任何行相关。