Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 表格内填以下公式:
- =SWITCH(B2,"一星",IF(CheckConsecutiveColumns(E2:L2,">=",IF(D2="困难",85,95),6),"升级",IF(CheckConsecutiveColumns(E2:L2,"<",70,3),"优化","正常")),"二星",IF(CheckConsecutiveColumns(E2:L2,">=",IF(D2="困难",85,95),9),"升级",IF(CheckConsecutiveColumns(E2:L2,"<",75,3),"降级","正常")),"三星",IF(CheckConsecutiveColumns(E2:L2,"<",80,3),"降级","正常"),"四星",IF(CheckConsecutiveColumns(E2:L2,"<",IF(D2="困难",70,85),3),"降级","正常"),"五星",IF(CheckConsecutiveColumns(E2:L2,"<",IF(D2="困难",70,85),3),"降级","正常"),"优化","优化","转岗","转岗","——","——")
- vba 填以下代码:
- 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 <> ">" 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
- If IsError(rng.Cells(1, j).Value) Then
- count = 0
- ElseIf rng.Cells(1, j).Value = Empty Then
- count = 0
- Else
- result = executeOp(rng.Cells(1, j).Value, op, num)
- If result Then
- count = count + 1
- Else
- count = 0
- End If
- 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 String, op As String, num As Double) As Boolean
- If op = "=" Then
- executeOp = (x = num)
- ElseIf op = "<" Then
- executeOp = (x < num)
- ElseIf op = ">" Then
- executeOp = (x > num)
- ElseIf op = ">=" Then
- executeOp = (x >= num)
- ElseIf op = "<=" Then
- executeOp = (x <= num)
- End If
- End Function
Add Comment
Please, Sign In to add comment