我想在工作表中设置公式或VBA脚本(可能更可能需要VBA脚本),该工作表将检查行中的日期并将其复制到特定单元格中,然后再向下移动到下一行
示例:
Search row K8 - ZZ8 for a date
Copy the first date found into cell I8
Search row K9 - ZZ9 for a date
Copy the first date found into cell I9
Repeat until row 938, inclusive.
如果没有大量的工作,这可能吗?我将如何去做?我必须承认,我对VBA一无所知,或者在使用excel方面有很多知识!!
答案 0 :(得分:1)
这是一个有效的代码:
Option Explicit
Sub findDate()
Dim v As Variant
Dim i As Integer, j As Integer
v = ActiveWorkbook.Worksheets("Sheet1").Range("K8:ZZ938")
'Loop over the rows
For i = 1 To UBound(v, 1)
'Loop over the columns
For j = 1 To UBound(v, 2)
If IsDate(v(i, j)) Then
ActiveWorkbook.Worksheets("Sheet1").Cells(i, "I") = v(i, j)
Exit For
End If
Next j
Next i
End Sub
该过程将遍历该行的每一行和每一列以查找第一个日期,并在找到日期时退出行循环。
注意使用数组将值放入其中,以便程序相当快。