我有一个基于Box A3:A中的每个单元格(如果CDate(Cell.Value)<2年)的列表框。
基本上查看A3列,直到小于2年的日期中最后一个使用的单元格的日期,如果对ListBox为true,则从相邻的B列返回值。
谢谢。
userRef
答案 0 :(得分:0)
试试看
Dim MyDateYear As Date
Dim Cell As Range
Dim LRow as Long
MyDateYear = Date
MyDateYear = DateAdd("m", -24, MyDateYear)
With Workbooks(REF).Sheets("Sheet1") 'edit reference
LRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For Each Cell In .Range("A3:A" & LRow)
If CDate(Cell.Value) < Format(MyDateYear, "YYYY") Then
Me.ListBox1.AddItem .Cells(Cell.Row, 2).Value
End If
Next Cell
End With
有关获取最后一个单元格,行,列的更多信息,请阅读this article