Excel精英培训网

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

[已解决]31天中判断“A,B,C”开头之间距离

[复制链接]
发表于 2014-5-21 22:48 | 显示全部楼层 |阅读模式
距离.zip (10.84 KB, 下载次数: 19)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2014-5-22 01:44 | 显示全部楼层
本帖最后由 cbg2008 于 2014-5-22 01:51 编辑

不会
回复

使用道具 举报

发表于 2014-5-22 10:58 | 显示全部楼层
  1. Sub tt()
  2.     Range("ag:ag").ClearContents
  3.     arr = [a1].CurrentRegion
  4.     For i = 2 To UBound(arr)
  5.         xstr = "":  n = 0: s = 0
  6.         For j = 1 To UBound(arr, 2)
  7.             x = Left(arr(i, j), 1)
  8.             If InStr("ABC", x) > 0 And Len(x) > 0 Then
  9.                 s = s + 1
  10.             Else
  11.                 If s >= 7 Then
  12.                     n = n + 1
  13.                     xstr = xstr & "," & Cells(i, j - 1).Address
  14.                 End If
  15.                 s = 0
  16.             End If
  17.         Next
  18.         If n > 0 Then
  19.             Cells(i, "ag") = "已有" & n & "次超出7天,是" & Mid(Replace(xstr, "$", ""), 2)
  20.         Else
  21.             Cells(i, "ag") = "无"
  22.         End If
  23.     Next
  24. End Sub


复制代码
回复

使用道具 举报

发表于 2014-5-22 11:05 | 显示全部楼层    本楼为最佳答案   
请看附件。附件里代码略有改动,考虑了最大列的边界问题。
  1. Sub tt()
  2.     Range("ag:ag").ClearContents
  3.     arr = [a1].CurrentRegion
  4.     For i = 2 To UBound(arr)
  5.         xstr = "":  n = 0: s = 0
  6.         For j = 1 To UBound(arr, 2)
  7.             x = Left(arr(i, j), 1)
  8.             If InStr("ABC", x) > 0 And Len(x) > 0 Then
  9.                 s = s + 1
  10.             Else
  11.                 If s >= 7 Then
  12.                     n = n + 1
  13.                     xstr = xstr & "," & Cells(i, j - 1).Address
  14.                 End If
  15.                 s = 0
  16.             End If
  17.             If j = UBound(arr, 2) And s >= 7 Then
  18.                  n = n + 1
  19.                  xstr = xstr & "," & Cells(i, j).Address
  20.             End If
  21.         Next
  22.         If n > 0 Then
  23.             Cells(i, "ag") = "已有" & n & "次超出7天,是" & Mid(Replace(xstr, "$", ""), 2)
  24.         Else
  25.             Cells(i, "ag") = "无"
  26.         End If
  27.     Next
  28. End Sub

复制代码

距离.rar

20 KB, 下载次数: 2

回复

使用道具 举报

发表于 2014-5-22 11:13 | 显示全部楼层
进来看下他人的代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 16:54 , Processed in 0.307830 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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