【问题标题】:Excel if cell contain "-" near number then moveExcel 如果单元格在数字附近包含“-”然后移动
【发布时间】:2017-02-18 20:00:36
【问题描述】:

我需要做的基本上是写课号。有3列。

第二列由我在 stackoverflow 上的第二个线程中的某人完成的名为 LessonsLeft 的自定义公式运行,它是

    Function LessonsLeft(rng As Range) As String
If rng.Count > 1 Then Exit Function
Dim spltStr() As String
Dim i As Long
spltStr = Split(rng.Value, ",")
LessonsLeft = ",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,"
For i = LBound(spltStr) To UBound(spltStr)
    LessonsLeft = Replace(LessonsLeft, "," & spltStr(i) & ",", ",")
Next i
LessonsLeft = Mid(LessonsLeft, 2, Len(LessonsLeft) - 2)
End Function

我需要做的是添加另一个第三列,这是我的学生第一次尝试但他们无法通过考试的课程。

我希望数据在那里,例如在第一列中的数字附近写一个“-”或“+”,这样数字将移动到第三列。

怎么做?

【问题讨论】:

  • 我的意思是,例如,如果我在第一列“5-”中写入,那么 5 将出现在第三列中

标签: vba excel


【解决方案1】:

使用此功能

Function LessonsAttemptedButNotDone(rng As Range) As String
    If rng.Count > 1 Then Exit Function
    Dim spltStr() As String, lessonDone As String
    Dim i As Long

    spltStr = Split(rng.Value, ",")
    For i = LBound(spltStr) To UBound(spltStr)
        lessonDone = spltStr(i)
        If Right(lessonDone, 1) = "-" Then
            lessonDone = Left(lessonDone, Len(lessonDone) - 1)
            LessonsAttemptedButNotDone = LessonsAttemptedButNotDone & lessonDone & ","
        End If
    Next
    If LessonsAttemptedButNotDone <> "" Then LessonsAttemptedButNotDone = Left(LessonsAttemptedButNotDone, Len(LessonsAttemptedButNotDone) - 1)
End Function

【讨论】:

  • 这就是工作。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多