簡體   English   中英

Excel如果單元格在數字附近包含“-”,然后移動

[英]Excel if cell contain “-” near number then move

我需要做的基本上是寫課程號。 有3個欄目。 在此處輸入圖片說明

第二列由一個名為LessonsLeft的自定義公式運行,該公式由我在stackoverflow上的第二個線程完成,

    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

我需要做的是添加另一個第三列,該列是關於我的學生進行了第一次嘗試但未通過考試的課程。

我希望數據在那里,例如在第一列中的數字附近寫一個“-”或“ +”,這樣數字將移至第三列。

如何做呢 ?

使用這個功能

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM