Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2010|回复: 1

[已解决]各位大侠,请问谁能通知VBA匹配出重复的时间段?

[复制链接]
发表于 2012-10-17 21:38 | 显示全部楼层 |阅读模式
条件一:先匹配出为同一天:
条件二:同一天内有共同时间段的,EXCEL中单元格标黄色。
(详细见附件)
最佳答案
2012-10-17 22:56
本帖最后由 森林狼 于 2012-10-17 23:00 编辑

  Range("C2:D60000").Interior.ColorIndex = xlNone
  
  Dim x, y
For x = 2 To Range("a65536").End(xlUp).Row
For y = x + 1 To Range("a65536").End(xlUp).Row
If Cells(y, 2) = Cells(x, 2) And ((Cells(y, 3) < Cells(x, 4) And Cells(y, 3) >= Cells(x, 3)) Or (Cells(y, 4) <= Cells(x, 4) And Cells(y, 4) > Cells(x, 3))) Then
Cells(x, 3).Interior.ColorIndex = 6
Cells(x, 4).Interior.ColorIndex = 6
Cells(y, 3).Interior.ColorIndex = 6
Cells(y, 4).Interior.ColorIndex = 6
Else
End If
Next
Next

Book2.zip

9.14 KB, 下载次数: 12

时间匹配

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-10-17 22:56 | 显示全部楼层    本楼为最佳答案   
本帖最后由 森林狼 于 2012-10-17 23:00 编辑

  Range("C2:D60000").Interior.ColorIndex = xlNone
  
  Dim x, y
For x = 2 To Range("a65536").End(xlUp).Row
For y = x + 1 To Range("a65536").End(xlUp).Row
If Cells(y, 2) = Cells(x, 2) And ((Cells(y, 3) < Cells(x, 4) And Cells(y, 3) >= Cells(x, 3)) Or (Cells(y, 4) <= Cells(x, 4) And Cells(y, 4) > Cells(x, 3))) Then
Cells(x, 3).Interior.ColorIndex = 6
Cells(x, 4).Interior.ColorIndex = 6
Cells(y, 3).Interior.ColorIndex = 6
Cells(y, 4).Interior.ColorIndex = 6
Else
End If
Next
Next
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-29 13:11 , Processed in 0.417542 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表