您好我想在我的VBA代码中实现一个公式。它应检查列中的所有值是否相同。
Dim intBB2 As Integer
Dim LastRow As Long
Dim ISINcheck As String
ISINcheck = WorksheetFunction.CountIf(ActiveWorkbook.Sheets(1).Range(Cells(2, intBB2), Cells(LastRow, intBB2)), _
ActiveWorkbook.Sheets(1).Range(Cells(2, intBB2))) _
= WorksheetFunction.CountA(ActiveWorkbook.Sheets(1).Range(Cells(2, intBB2), Cells(LastRow, intBB2)))
变量intBB2
和LastRow
来自之前的代码,它找到最后一行和列,公式应该用于计算。
如果我用范围的地址(例如I2:I120)替换范围引用,它就可以工作。但事实上,它给了我一个应用程序定义或对象定义的错误。
答案 0 :(得分:0)
试试这个。您需要使用工作簿/工作表来限定所有范围
With ActiveWorkbook.Sheets(1)
ISINcheck = WorksheetFunction.CountIf(.Range(.Cells(2, intBB2), .Cells(LastRow, intBB2)), _
.Range(.Cells(2, intBB2))) _
= WorksheetFunction.CountA(.Range(.Cells(2, intBB2), .Cells(LastRow, intBB2)))
End With
答案 1 :(得分:0)
解决这个问题
intValueToFind = Cells(2, intBB2).Value
For i = 2 To LastRow
If Not Cells(i, intBB2).Value = intValueToFind Then
ISINcheck = i
End If
Next i
If ISINcheck = "" Then
controlISIN = "N"
Else
controlISIN = "Y"
End If
可能不是最优雅但有效的