【发布时间】:2016-01-14 21:58:18
【问题描述】:
我正在尝试制作一个在列中搜索相同值的 vba 代码,然后从 B 列返回最新日期 例如:
column A B output C
-------------------------------------
102 12.01.2016 12.01.2016
102 17.10.2015
102 25.12.2015
105 30.03.2015
105 01.01.2016 01.01.2016
它应该在 A 列中搜索不同的值。如果它一个接一个地找到相同的值,那么它将从对应的B列中搜索最新的日期并在C列中输出 请帮我一个vba代码。 谢谢你
Sub Cauta()
'Finds the last non-blank cell in a single row or column
Dim lRow As Long
Dim lCol As Long
Dim k, t, i, j As Long
Dim stvalue As Integer
Dim lsvalue As Integer
Dim data As Date
'Find the last non-blank cell in column A(1)
lRow = Cells(Rows.Count, 2).End(xlUp).row
For i = 2 To lRow
stvalue = Cells(i, 2)
t = 0
For j = i To lRow
If stvalue = Cells(j + 1, 2) Then
t = t + 1
Else: j = lRow
data = Cells(j, 3)
For k = i To i + t
If Cells(k, 3) < Cells(k + 1, 3) Then data = Cells(k + 1, 3)
Next k
Cells(i + t, 6).Value = data
End If
Next j
i = i + t
Next i
End Sub
【问题讨论】:
-
你没有附上你的代码
-
为什么需要 VBA?诸如
=MAX(B2:B10)之类的公式将给出您寻求的结果。 -
抱歉,现在不知道如何附加代码。
-
要包含代码:单击问题下方的编辑按钮。 Cody 并将您的代码粘贴到编辑窗口中。