如何在VBA中为每个循环获取索引(使用Excel编程)?

AGa*_*yer 2 excel vba excel-vba

我正在使用EXCEL VBA处理一些数据,这是我要制作的:

我想开发一个可以计算出浅绿色区域中的值的函数

在此工作表中,我想创建一个函数“ GetDebutDate”,该函数可以自动计算该行具有值的第一个日期。

例如,在“标记”行中,第一次获取值的时间是08年8月,数字为“ 4”。

我对VBA知之甚少,在四处搜寻之后,我发现可以For ... Each循环使用范围。但是,如何获取每个循环中“ v”的索引?获得该索引后,如何获得第一行中的Date值?

Function Get_Board_Count(range As range)
  For Each v In range
    ....
  Next
  Get_Board_Count = ....
End Function
Run Code Online (Sandbox Code Playgroud)

sha*_*esh 5

Function Get_Board_Count(range As range)
    dim i as integer
    i = 1

    for each v in Range
       ...
       i = i + 1
    next


  Get_Board_Count = i 'Index of the item where cell is found.
End Function
Run Code Online (Sandbox Code Playgroud)