Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 查找列中的所有值并检索数组中的地址_Excel_Vba - Fatal编程技术网

Excel 查找列中的所有值并检索数组中的地址

Excel 查找列中的所有值并检索数组中的地址,excel,vba,Excel,Vba,我想使用VBA中的.find函数来查找列中某个值的实例,但是,有些计算是基于找到该值所在行的条件进行的。这是有问题的,因为尽管我所寻找的值可能是相同的,但用于创建总体分数的标准是不同的。因此,我需要遍历列中的所有值,我想知道如何在vba中实现这一点。我知道findnext函数,但我无法让它正常工作 counted = Application.WorksheetFunction.CountIfs(cl.Range(finletter & "9:" & finletter &

我想使用VBA中的.find函数来查找列中某个值的实例,但是,有些计算是基于找到该值所在行的条件进行的。这是有问题的,因为尽管我所寻找的值可能是相同的,但用于创建总体分数的标准是不同的。因此,我需要遍历列中的所有值,我想知道如何在vba中实现这一点。我知道findnext函数,但我无法让它正常工作

 counted = Application.WorksheetFunction.CountIfs(cl.Range(finletter & "9:" & finletter & "317"), "Value", cl.Range("H9:H317"), wl.Range("A" & y.row).Value)
        'Pol small low complex
        If counted > 0 Then
            MsgBox wl.Range("A" & y.row).Value
        If cl.Range("C" & y.row).Value < 3 And cl.Range("D" & y.row).Value = 1 And cl.Range("E" & y.row).Value = "Interim" Then

        wl.Range(y.Address) = 3.75 * counted
counted=Application.WorksheetFunction.CountIfs(cl.Range(finletter&“9:”&finletter&“317”)、“Value”、cl.Range(“H9:H317”)、wl.Range(“A”&y.row).Value)
"Pol小低综合体"
如果计数大于0,则
MsgBox wl.Range(“A”和y.row).值
如果cl.Range(“C”和y.row).Value<3,cl.Range(“D”和y.row).Value=1,cl.Range(“E”和y.row).Value=“中间”,则
wl.范围(y.地址)=3.75*已计数

以下是一个示例。假设我们在A列中查找文本“LOVE”,并处理这些行上的数据:

Option Base 1

Sub LookingForLove()
    Dim s As String, rng As Range, WhichRows() As Long
    Dim rFound As Range

    ReDim WhichRows(1)

    s = "LOVE"
    Set rng = Range("A1:A25")
    Set rFound = rng.Find(What:=s, After:=rng(1))
    WhichRows(1) = rFound.Row

    Do
        Set rFound = rng.FindNext(After:=rFound)
        If rFound.Row = WhichRows(1) Then Exit Do
        ReDim Preserve WhichRows(UBound(WhichRows) + 1)
        WhichRows(UBound(WhichRows)) = rFound.Row
    Loop

    msg = UBound(WhichRows) & vbCrLf & vbCrLf
    For i = 1 To UBound(WhichRows)
        msg = msg & WhichRows(i) & vbCrLf
    Next i

    MsgBox msg
End Sub

注:

  • 退出Do
    可防止永远循环
  • 通过循环
    WhichRows()
    的元素并处理这些行上的项目,代码将继续
  • 您的代码也可以创建范围或单元格地址的动态数组
另一种替代方法是使用VBA建立一个自动过滤器,并处理可见行