Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Function CheckConsecutiveColumns(rng As Range, op As String, num As Double, n As Integer) As Boolean
- Dim i As Integer
- Dim j As Integer
- Dim count As Integer
- Dim totalColumns As Integer
- Dim result As Boolean
- If op <> "=" And op <> "<" And op <> ">" Then
- MsgBox ("op 只允许为 >, <, = 中的一个")
- CheckConsecutiveColumns = rng
- End If
- ' 计算总列数
- totalColumns = rng.Columns.count
- ' 检查每一列
- For i = 1 To totalColumns - n + 1
- ' 初始化计数器
- count = 0
- ' 检查连续的 n 列
- For j = i To totalColumns
- result = executeOp(rng.Cells(1, j).Value, op, num)
- If result Then
- count = count + 1
- Else
- count = 0
- End If
- ' 如果找到连续的 n 列,则返回 True
- If count = n Then
- CheckConsecutiveColumns = True
- Exit Function
- End If
- Next j
- Next i
- ' 如果没有找到连续的 m 列,则返回 False
- CheckConsecutiveColumns = False
- End Function
- Function executeOp(x As Double, op As String, num As Double) As Boolean
- If op = "=" Then
- executeOp = (x = num)
- ElseIf op = "<" Then
- executeOp = (x < num)
- Else
- executeOp = (x > num)
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement