我有两组时间序列(dd/mm/yyyy),可能在不同的时间段开始和结束。我想在另一个单元格中报告所有重叠的日期和与它们相关的相关数据,它们都存在于两个列中。
下面的图片准确地解释了我拥有的数据以及我想要用它做什么。

选择两列,创建变量并启动"foreach“循环,我不知道执行这些命令的代码结构。
Sub overlap()
Dim c As Range
For Each c In Selection
If c.Value
Next c
End Sub发布于 2019-02-17 21:43:54
未经测试,但应该是这样的:
Option Explicit
Sub Overlap()
Dim wb As Workbook
Dim ws As Worksheet
Dim LastRow As Long, LastCol As Long
Dim rng As Range, Rng2 As Range
Dim Cell As Variant, Double As Variant
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Whatever")
LastRow = ws.Cells(wsV.Rows.Count, "A").End(xlUp).row
Lastcol = ws.Cells(1, .Columns.Count).End(xlToLeft).Column
'Your entire range, here in column A
Rng = ws.Range(ws.Cells(1, 1), ws.Cells(LastRow, LastCol))
' Loop through each cell of the Range
For Each Cell in Rng
'Set a new range, from the beginning of the orginal one to your current row
Set Rng2 = ws.Range(ws.Cells(1,1), ws.Cells(Cell.Row,1))
With Rng2
Set Double = .Find(Cell.Value, LookIn:=xlValues, Lookat:=xlWhole)
' If double is not nothing you've found the value of the current cell
' Meaning there's more than one
If Not Double Is Nothing Then
'Here you found a duplicate value - Do what you need to do
End If
End With
Next Cell
End Subhttps://stackoverflow.com/questions/54733757
复制相似问题